private void readDomain(String element, XMLElement datadict) {

    for (int df = 0; df < datadict.getChildCount(); df++) {
      if (datadict.getChild(df).getStringAttribute("name").equals(element)) {

        // add the prob for each node
        String[] probs = {};
        for (int val = 0; val < datadict.getChild(df).getChildCount(); val++) {
          if (datadict.getChild(df).getChild(val).getName().equals("Extension")) {
            XMLElement ext = datadict.getChild(df).getChild(val);

            for (int x = 0; x < ext.getChildCount(); x++) {
              if (ext.getChild(x).getName().equals("X-Definition")) {
                probs = ext.getChild(x).getChild(0).getContent().split(" ");
                break;
              }
            }

            break;
          }
        }

        // create a node for each value
        int valIdx = 0;
        for (int val = 0; val < datadict.getChild(df).getChildCount(); val++) {
          if (datadict.getChild(df).getChild(val).getName().equals("Value")) {
            float prob = Float.valueOf(probs[valIdx++]);
            //
            //	this.addNode(datadict.getChild(df).getChild(val).getStringAttribute("value")).setProb(prob);

            if (!this.domains.containsKey(element))
              this.domains.put(element, new ArrayList<String>());

            if (!this.probabilities.containsKey(element))
              this.probabilities.put(element, new HashMap<String, Float>());

            this.domains
                .get(element)
                .add(datadict.getChild(df).getChild(val).getStringAttribute("value"));
            this.probabilities
                .get(element)
                .put(datadict.getChild(df).getChild(val).getStringAttribute("value"), prob);
          }
        }

        break;
      }
    }
  }
Ejemplo n.º 2
0
  /** Loads track segments of a GPX file, and returns them as a single line marker. */
  public static List<Feature> loadData(PApplet p, String gpxFilename) {
    List<Feature> trackFeatures = new ArrayList<Feature>();

    // Load GPX file
    XMLElement gpx = new XMLElement(p, gpxFilename);

    // Create track with all track points
    ShapeFeature trackFeature = new ShapeFeature(FeatureType.LINES);

    XMLElement[] itemXMLElements = gpx.getChildren("trk/trkseg/trkpt");
    for (int i = 0; i < itemXMLElements.length; i++) {
      // Adds location for track point
      float lat = itemXMLElements[i].getFloat("lat");
      float lon = itemXMLElements[i].getFloat("lon");
      Location location = new Location(lat, lon);
      trackFeature.addLocation(location);
    }

    // Add time as property
    XMLElement timeXMLElement = gpx.getChild("trk/time");
    trackFeature.addProperty("time", timeXMLElement.getContent());

    trackFeatures.add(trackFeature);
    return trackFeatures;
  }
Ejemplo n.º 3
0
/*      */   public boolean equals(Object object)
/*      */   {
/* 1350 */     if (!(object instanceof XMLElement)) {
/* 1351 */       return false;
/*      */     }
/* 1353 */     XMLElement rawElement = (XMLElement)object;
/*      */     
/* 1355 */     if (!this.name.equals(rawElement.getLocalName())) {
/* 1356 */       return false;
/*      */     }
/* 1358 */     if (this.attributes.size() != rawElement.getAttributeCount()) {
/* 1359 */       return false;
/*      */     }
/* 1361 */     Enumeration<XMLAttribute> en = this.attributes.elements();
/* 1362 */     while (en.hasMoreElements()) {
/* 1363 */       XMLAttribute attr = (XMLAttribute)en.nextElement();
/*      */       
/* 1365 */       if (!rawElement.hasAttribute(attr.getName())) {
/* 1366 */         return false;
/*      */       }
/*      */       
/*      */ 
/*      */ 
/* 1371 */       String value = rawElement.getString(attr.getName(), null);
/* 1372 */       if (!attr.getValue().equals(value)) {
/* 1373 */         return false;
/*      */       }
/*      */     }
/*      */     
/*      */ 
/*      */ 
/*      */ 
/*      */ 
/* 1381 */     if (this.children.size() != rawElement.getChildCount()) {
/* 1382 */       return false;
/*      */     }
/* 1384 */     for (int i = 0; i < this.children.size(); i++) {
/* 1385 */       XMLElement child1 = getChild(i);
/* 1386 */       XMLElement child2 = rawElement.getChild(i);
/*      */       
/* 1388 */       if (!child1.equals(child2)) {
/* 1389 */         return false;
/*      */       }
/*      */     }
/* 1392 */     return true;
/*      */   }
Ejemplo n.º 4
0
  public void initXMLObject() {

    numProfiles = xmlFeed.getChildCount();
    println("NUM PROFILES: " + numProfiles);
    for (int i = 0; i < numProfiles; i++) {
      XMLElement profile = xmlFeed.getChild(i);
      /// *
      try {
        headerList.add(profile.getChild(0).getContent());
        nameList.add(profile.getChild(1).getContent());
        blurbList.add(profile.getChild(2).getContent());
        // videoPathList.add(profile.getChild(3).getContent());
        thePopUp.videoPath.add(profile.getChild(3).getContent());
        latList.add(profile.getChild(4).getContent());
        longList.add(profile.getChild(5).getContent());

        pApp.println("Title= " + profile.getChild(0).getContent());
        pApp.println("Name= " + profile.getChild(1).getContent());
        pApp.println("Blurb= " + profile.getChild(2).getContent());
        // pApp.println("video = " +  profile.getChild(3).getContent());
        pApp.println("Address = " + profile.getChild(4).getContent());
        // pApp.println("long = " + profile.getChild(5).getContent());
        // pApp.println(" ");
        pApp.println(" ");
      } catch (Exception e) {
        println("XML init error: " + e);
      }
    }
    /// now that the popup video array has data, init the video
    thePopUp.initVideo();
    /// convert the lat and long string to floats
    initLocations();
  }
  public void loadData() {

    XMLElement xml = new XMLElement(this, filename);

    // pmml
    for (int i = 0; i < xml.getChildCount(); i++) {

      if (!xml.getChild(i).getName().equals("DataDictionary")) {
        continue;
      }

      XMLElement datadict = xml.getChild(i);

      // read node domains from PMML
      readDomain(actionT, datadict);
      readDomain(objActedOn, datadict);
      readDomain(toLocation, datadict);
      readDomain(errorT, datadict);
      readDomain(groupT, datadict);
      readDomain(fromLocation, datadict);

      // TODO: create separate graphs for each activity

      ///////////////////////////////////////
      // read edges

      // find precedes predicate
      for (int df = 0; df < datadict.getChildCount(); df++) {
        if (datadict.getChild(df).getStringAttribute("name").equals(precedes)) {

          // find Extension module
          for (int val = 0; val < datadict.getChild(df).getChildCount(); val++) {
            if (datadict.getChild(df).getChild(val).getName().equals("Extension")) {
              XMLElement ext = datadict.getChild(df).getChild(val);

              // find the X-Table inside the X-Definition
              for (int x = 0; x < ext.getChildCount(); x++) {
                if (ext.getChild(x).getName().equals("X-Definition")) {

                  for (int xx = 0; xx < ext.getChild(x).getChildCount(); xx++) {
                    if (!ext.getChild(x).getChild(xx).getName().equals("X-Table")) {
                      continue;
                    }

                    // read all the cond. probabilities
                    String[] cpt = ext.getChild(x).getChild(xx).getContent().split(" ");

                    // iterate across the table of conditional probabilities and link the nodes
                    // accordingly

                    // healthinf-trials
                    //	<X-Given>0</X-Given> <!-- objActedOn(a1) -->
                    //	<X-Given>1</X-Given> <!-- errorT(e) -->
                    //	<X-Given>2</X-Given> <!-- groupT(g) -->
                    //	<X-Given>3</X-Given> <!-- toLocation(a1) -->
                    //	<X-Given>4</X-Given> <!-- actionT(a1) -->
                    //	<X-Given>6</X-Given> <!-- #actionT(a2) -->
                    //	<X-Given>7</X-Given> <!-- #objActedOn(a2) -->
                    //	<X-Given>8</X-Given> <!-- #toLocation(a2) -->
                    //	<X-Given>9</X-Given> <!-- !(a1=a2) -->
                    // int blocksize_obj1    = domains.get(errorT).size() *
                    // domains.get(groupT).size() * domains.get(toLocation).size() *
                    // domains.get(actionT).size() * domains.get(actionT).size() *
                    // domains.get(objActedOn).size() * domains.get(toLocation).size();
                    // int blocksize_error   = domains.get(groupT).size() *
                    // domains.get(toLocation).size() * domains.get(actionT).size() *
                    // domains.get(actionT).size() * domains.get(objActedOn).size()  *
                    // domains.get(toLocation).size();
                    // int blocksize_group   = domains.get(toLocation).size() *
                    // domains.get(actionT).size() * domains.get(actionT).size() *
                    // domains.get(objActedOn).size()  * domains.get(toLocation).size();
                    // int blocksize_toLoc1  = domains.get(actionT).size() *
                    // domains.get(actionT).size() * domains.get(objActedOn).size()  *
                    // domains.get(toLocation).size();
                    // int blocksize_action1 = domains.get(actionT).size() *
                    // domains.get(objActedOn).size()  * domains.get(toLocation).size();
                    // int blocksize_action2 = domains.get(objActedOn).size()  *
                    // domains.get(toLocation).size();
                    // int blocksize_obj2    = domains.get(toLocation).size();
                    // int blocksize_toLoc2  = 1;

                    // healthinf-finals (incl. fromlocation)
                    //										<X-Given>0</X-Given> <!-- objActedOn(a1) -->
                    //										<X-Given>1</X-Given> <!-- errorT(e) -->
                    //										<X-Given>2</X-Given> <!-- groupT(g) -->
                    //										<X-Given>3</X-Given> <!-- fromLocation(a1) -->
                    //										<X-Given>4</X-Given> <!-- toLocation(a1) -->
                    //										<X-Given>5</X-Given> <!-- actionT(a1) -->
                    //										<X-Given>7</X-Given> <!-- #actionT(a2) -->
                    //										<X-Given>8</X-Given> <!-- #objActedOn(a2) -->
                    //										<X-Given>9</X-Given> <!-- #toLocation(a2) -->
                    //										<X-Given>10</X-Given> <!-- #fromLocation(a2) -->
                    //										<X-Given>11</X-Given> <!-- !(a1=a2) -->
                    int blocksize_obj1 =
                        domains.get(errorT).size()
                            * domains.get(groupT).size()
                            * domains.get(fromLocation).size()
                            * domains.get(toLocation).size()
                            * domains.get(actionT).size()
                            * domains.get(actionT).size()
                            * domains.get(objActedOn).size()
                            * domains.get(toLocation).size()
                            * domains.get(fromLocation).size();
                    int blocksize_error =
                        domains.get(groupT).size()
                            * domains.get(fromLocation).size()
                            * domains.get(toLocation).size()
                            * domains.get(actionT).size()
                            * domains.get(actionT).size()
                            * domains.get(objActedOn).size()
                            * domains.get(toLocation).size()
                            * domains.get(fromLocation).size();
                    int blocksize_group =
                        domains.get(fromLocation).size()
                            * domains.get(toLocation).size()
                            * domains.get(actionT).size()
                            * domains.get(actionT).size()
                            * domains.get(objActedOn).size()
                            * domains.get(toLocation).size()
                            * domains.get(fromLocation).size();
                    int blocksize_fromLoc1 =
                        domains.get(toLocation).size()
                            * domains.get(actionT).size()
                            * domains.get(actionT).size()
                            * domains.get(objActedOn).size()
                            * domains.get(toLocation).size()
                            * domains.get(fromLocation).size();
                    int blocksize_toLoc1 =
                        domains.get(actionT).size()
                            * domains.get(actionT).size()
                            * domains.get(objActedOn).size()
                            * domains.get(toLocation).size()
                            * domains.get(fromLocation).size();
                    int blocksize_action1 =
                        domains.get(actionT).size()
                            * domains.get(objActedOn).size()
                            * domains.get(toLocation).size()
                            * domains.get(fromLocation).size();
                    int blocksize_action2 =
                        domains.get(objActedOn).size()
                            * domains.get(toLocation).size()
                            * domains.get(fromLocation).size();
                    int blocksize_obj2 =
                        domains.get(toLocation).size() * domains.get(fromLocation).size();
                    int blocksize_toLoc2 = domains.get(fromLocation).size();
                    int blocksize_fromLoc2 = 1;

                    System.err.println("CPT size: " + cpt.length);

                    System.err.println(
                        "Domain sizes: "
                            + domains.get(objActedOn).size()
                                * domains.get(errorT).size()
                                * domains.get(groupT).size()
                                * domains.get(fromLocation).size()
                                * domains.get(toLocation).size()
                                * domains.get(actionT).size()
                                * domains.get(actionT).size()
                                * domains.get(objActedOn).size()
                                * domains.get(fromLocation).size()
                                * domains.get(toLocation).size());

                    for (int obj1 = 0; obj1 < domains.get(objActedOn).size(); obj1++) { // #elem 10
                      for (int error = 0; error < domains.get(errorT).size(); error++) { // #elem 1
                        for (int group = 0;
                            group < domains.get(groupT).size();
                            group++) { // #elem 1
                          for (int fromLoc1 = 0;
                              fromLoc1 < domains.get(fromLocation).size();
                              fromLoc1++) {
                            for (int toLoc1 = 0;
                                toLoc1 < domains.get(toLocation).size();
                                toLoc1++) { // #elem 5
                              for (int action1 = 0;
                                  action1 < domains.get(actionT).size();
                                  action1++) { // #elem 3
                                for (int action2 = 0;
                                    action2 < domains.get(actionT).size();
                                    action2++) { // #elem 3
                                  for (int obj2 = 0;
                                      obj2 < domains.get(objActedOn).size();
                                      obj2++) { // #elem 10
                                    for (int fromLoc2 = 0;
                                        fromLoc2 < domains.get(fromLocation).size();
                                        fromLoc2++) { // #elem 5
                                      for (int toLoc2 = 0;
                                          toLoc2 < domains.get(toLocation).size();
                                          toLoc2++) { // #elem 5

                                        // total: 1 166 400 blocks in the CPT, each block four
                                        // numbers ((a1=a2) plus true/false)

                                        // TODO: modify this loop to take the different parents into
                                        // account
                                        //       -> also read labels for parents and add separate
                                        // nodes for each combination

                                        float condA1A2 =
                                            Float.valueOf(
                                                cpt[
                                                    4
                                                        * (obj1 * blocksize_obj1
                                                            + error * blocksize_error
                                                            + group * blocksize_group
                                                            + fromLoc1 * blocksize_fromLoc1
                                                            + toLoc1 * blocksize_toLoc1
                                                            + action1 * blocksize_action1
                                                            + action2 * blocksize_action2
                                                            + obj2 * blocksize_obj2
                                                            + fromLoc2 * blocksize_fromLoc2
                                                            + toLoc2 * blocksize_toLoc2)]);

                                        if (condA1A2 > 0.0) {

                                          // search for nodes, create if don't exist yet
                                          Node from = null;

                                          // use toLocation only if not empty
                                          if (!domains.get(toLocation).get(toLoc1).equals("No_from")
                                              && !domains
                                                  .get(toLocation)
                                                  .get(toLoc1)
                                                  .equals("No_to")) {

                                            from =
                                                this.findNode(
                                                    domains.get(actionT).get(action1)
                                                        + " "
                                                        + domains.get(objActedOn).get(obj1)
                                                        + " to "
                                                        + domains.get(toLocation).get(toLoc1));

                                            from.prob =
                                                probabilities
                                                        .get(actionT)
                                                        .get(domains.get(actionT).get(action1))
                                                    * probabilities
                                                        .get(objActedOn)
                                                        .get(domains.get(objActedOn).get(obj1))
                                                    * probabilities
                                                        .get(toLocation)
                                                        .get(domains.get(toLocation).get(toLoc1));

                                            if (from.prob > 0.000002) {
                                              System.err.println(
                                                  from.getName()
                                                      + ": "
                                                      + probabilities
                                                          .get(actionT)
                                                          .get(domains.get(actionT).get(action1))
                                                      + " * "
                                                      + probabilities
                                                          .get(objActedOn)
                                                          .get(domains.get(objActedOn).get(obj1))
                                                      + " * "
                                                      + probabilities
                                                          .get(toLocation)
                                                          .get(
                                                              domains.get(toLocation).get(toLoc1)));
                                            }

                                          } else if (!domains
                                                  .get(fromLocation)
                                                  .get(fromLoc1)
                                                  .equals("No_from")
                                              && !domains
                                                  .get(fromLocation)
                                                  .get(fromLoc1)
                                                  .equals("No_to")) {

                                            from =
                                                this.findNode(
                                                    domains.get(actionT).get(action1)
                                                        + " "
                                                        + domains.get(objActedOn).get(obj1)
                                                        + " from "
                                                        + domains.get(fromLocation).get(fromLoc1));

                                            from.prob =
                                                probabilities
                                                        .get(actionT)
                                                        .get(domains.get(actionT).get(action1))
                                                    * probabilities
                                                        .get(objActedOn)
                                                        .get(domains.get(objActedOn).get(obj1))
                                                    * probabilities
                                                        .get(fromLocation)
                                                        .get(
                                                            domains
                                                                .get(fromLocation)
                                                                .get(fromLoc1));

                                            if (from.prob > 0.000002) {
                                              System.err.println(
                                                  from.getName()
                                                      + ": "
                                                      + probabilities
                                                          .get(actionT)
                                                          .get(domains.get(actionT).get(action1))
                                                      + " * "
                                                      + probabilities
                                                          .get(objActedOn)
                                                          .get(domains.get(objActedOn).get(obj1))
                                                      + " * "
                                                      + probabilities
                                                          .get(fromLocation)
                                                          .get(
                                                              domains
                                                                  .get(fromLocation)
                                                                  .get(fromLoc1)));
                                            }
                                          }

                                          if (from != null)
                                            System.err.println(from.getName() + ": " + from.prob);

                                          Node to = null;
                                          if (!domains.get(toLocation).get(toLoc2).equals("No_from")
                                              && !domains
                                                  .get(toLocation)
                                                  .get(toLoc2)
                                                  .equals("No_to")) {

                                            to =
                                                this.findNode(
                                                    domains.get(actionT).get(action2)
                                                        + " "
                                                        + domains.get(objActedOn).get(obj2)
                                                        + " to "
                                                        + domains.get(toLocation).get(toLoc2));

                                            to.prob =
                                                probabilities
                                                        .get(actionT)
                                                        .get(domains.get(actionT).get(action2))
                                                    * probabilities
                                                        .get(objActedOn)
                                                        .get(domains.get(objActedOn).get(obj2))
                                                    * probabilities
                                                        .get(toLocation)
                                                        .get(domains.get(toLocation).get(toLoc2));

                                            if (to.prob > 0.000002) {
                                              System.err.println(
                                                  to.getName()
                                                      + ": "
                                                      + probabilities
                                                          .get(actionT)
                                                          .get(domains.get(actionT).get(action2))
                                                      + " * "
                                                      + probabilities
                                                          .get(objActedOn)
                                                          .get(domains.get(objActedOn).get(obj2))
                                                      + " * "
                                                      + probabilities
                                                          .get(toLocation)
                                                          .get(
                                                              domains.get(toLocation).get(toLoc2)));
                                            }

                                          } else if (!domains
                                                  .get(fromLocation)
                                                  .get(fromLoc2)
                                                  .equals("No_from")
                                              && !domains
                                                  .get(fromLocation)
                                                  .get(fromLoc2)
                                                  .equals("No_to")) {

                                            to =
                                                this.findNode(
                                                    domains.get(actionT).get(action2)
                                                        + " "
                                                        + domains.get(objActedOn).get(obj2)
                                                        + " from "
                                                        + domains.get(fromLocation).get(fromLoc2));

                                            to.prob =
                                                probabilities
                                                        .get(actionT)
                                                        .get(domains.get(actionT).get(action2))
                                                    * probabilities
                                                        .get(objActedOn)
                                                        .get(domains.get(objActedOn).get(obj2))
                                                    * probabilities
                                                        .get(fromLocation)
                                                        .get(
                                                            domains
                                                                .get(fromLocation)
                                                                .get(fromLoc2));

                                            if (to.prob > 0.000002) {
                                              System.err.println(
                                                  to.getName()
                                                      + ": "
                                                      + probabilities
                                                          .get(actionT)
                                                          .get(domains.get(actionT).get(action2))
                                                      + " * "
                                                      + probabilities
                                                          .get(objActedOn)
                                                          .get(domains.get(objActedOn).get(obj2))
                                                      + " * "
                                                      + probabilities
                                                          .get(fromLocation)
                                                          .get(
                                                              domains
                                                                  .get(fromLocation)
                                                                  .get(fromLoc2)));
                                            }
                                          }

                                          if (to != null) {
                                            System.err.println(to.getName() + ": " + to.prob);
                                            //																						System.err.println(to.getName()
                                            // + ": "
                                            // probabilities.get(domains.get(actionT).get(action2)));
                                          }

                                          if (from != null && to != null)
                                            this.addEdge(from.label, to.label, condA1A2);
                                        }
                                      }
                                    }
                                  }
                                }
                              }
                            }
                          }
                        }
                      }
                    }

                    break;
                  }
                }
              }

              break;
            }
          }
          break;
        }
      }
    }
  }
Ejemplo n.º 6
0
  /* The format of the grid parameters is the following:
   *   <grid>
   *       <resolution nx=10 ny=10></resolution>
   *      <point>
   *          <coord x="0.5" y="+0.5"></coord>
   *          <texcoord s="0.0" t="1.0"></texcoord>
   *      </point>
   *      <point>
   *          <coord x="x" y="y"></coord>
   *          <texcoord s="s" t="t"></texcoord>
   *      </point>
   *  </grid>
   */
  protected void initGrid(XMLElement xml) {
    int n = xml.getChildCount();

    // if there is only one parameter line, it should contain the
    // grid dimensions.
    if (n == 1) {
      numLayers = 1;
    } else {
      numLayers = n - 1;
    }

    points = new GLTexturedPoint[numLayers];

    XMLElement child;
    String name, wStr, hStr, modeName;
    int ptLayer = 0;
    for (int i = 0; i < n; i++) {
      child = xml.getChild(i);
      name = child.getName();
      if (name.equals("resolution")) {
        wStr = child.getStringAttribute("nx");
        hStr = child.getStringAttribute("ny");

        usingSrcTexRes = false;

        if (wStr.equals("w")) resX = 0;
        else if (wStr.equals("w0")) resX = -1;
        else if (wStr.equals("w1")) resX = -2;
        else if (wStr.equals("w2")) resX = -3;
        else if (wStr.equals("w3")) resX = -4;
        else if (wStr.equals("w4")) resX = -5;
        else if (wStr.equals("w5")) resX = -6;
        else resX = child.getIntAttribute("nx");

        if (hStr.equals("h")) resY = 0;
        else if (hStr.equals("h0")) resY = -1;
        else if (hStr.equals("h1")) resY = -2;
        else if (hStr.equals("h2")) resY = -3;
        else if (hStr.equals("h3")) resY = -4;
        else if (hStr.equals("h4")) resY = -5;
        else if (hStr.equals("h5")) resY = -6;
        else resY = child.getIntAttribute("ny");

        if ((resX <= 0) || (resY <= 0))
          if (resX != resY) System.err.println("Source width and height are different!");
          else if (resX < 0) {
            usingSrcTexRes = true;
            srcTexIdx = -(resX + 1);
          }

        modeName = child.getStringAttribute("mode");
        mode = GLUtils.parsePrimitiveType(modeName);
      } else if (name.equals("point")) {
        points[ptLayer] = new GLTexturedPoint(child);
        ptLayer++;
      }
    }

    if (n == 1) {
      points[0] = new GLTexturedPoint();
      points[0].setAsUndefined();
    }
  }