예제 #1
0
  private String chooserQuery() {
    Random r = new Random();
    File experimentFile = new File(queryFile);
    SAXBuilder sb = new SAXBuilder();
    Document d = null;
    try {
      d = sb.build(experimentFile);
    } catch (JDOMException e) {
      e.printStackTrace();
    } catch (IOException e) {
      e.printStackTrace();
    }
    List<String> queries = new ArrayList<String>();

    Element jpameterTag = d.getRootElement();
    Element queriesTag = jpameterTag.getChild("queries");

    List<Element> query = queriesTag.getChildren();

    for (Element e : query) {
      Element type = e.getChild("type");
      if (Integer.parseInt(type.getValue()) == typeQuery + 1) {
        Element sql = e.getChild("sql");
        queries.add(sql.getValue());
      }
    }
    if (queries.size() > 0) return queries.get(r.nextInt(queries.size()));
    else return null;
  }
예제 #2
0
 @Test
 public void test_setCommands() {
   Map<String, Command> expected = new HashMap<String, Command>();
   for (Element tmp : expected_commands) {
     expected.put(
         tmp.getValue(),
         new Command(
             tmp.getValue(),
             Integer.parseInt(tmp.getAttributeValue("id")),
             tmp.getAttributeValue("type")));
   }
   Assert.assertEquals(expected, this.commands.getMapOfCommand());
 }
 private String get(XMLProperty p) {
   final Element child = getElement(p);
   if (child == null) {
     return "";
   }
   return child.getValue();
 }
예제 #4
0
  /**
   * get start and end elemnt form parent element
   *
   * @param elem _more_
   * @param ns _more_
   * @return list of times
   */
  public List<String> readSelectTime(Element elem, Namespace ns) {
    // look for stations

    Element region = elem.getChild("TimeSpan", ns);

    java.util.List regionInfo = region.getChildren();
    // lat, lon
    Element start = region.getChild("start", ns);
    String sv = start.getValue();
    Element end = region.getChild("end", ns);
    String ev = end.getValue();

    List<String> ll = new ArrayList<String>();
    ll.add(sv);
    ll.add(ev);
    return ll;
  }
 /**
  * Load all the deals in this element
  *
  * @param e an element that contains messages in XML format.
  */
 protected void loadDeals(Element e) {
   Element root = StringToElement.getElementFromString(e.getValue(), e.getName());
   for (Element d : root.getChildren()) {
     String owner = d.getChildText("owner");
     Element deal = d.getChild("Deal");
     addDeal(owner, new Contrat(deal));
   }
 }
예제 #6
0
  /**
   * get region from parent element
   *
   * @param elem _more_
   * @param ns _more_
   * @return _more_
   */
  public LatLonRect readSelectRegion(Element elem, Namespace ns) {
    Element region = elem.getChild("LatLonBox", ns);
    // lat, lon
    Element north = region.getChild("north", ns);
    String nv = north.getValue();
    Element south = region.getChild("south", ns);
    String sv = south.getValue();
    Element east = region.getChild("east", ns);
    String ev = east.getValue();
    Element west = region.getChild("west", ns);
    String wv = west.getValue();

    LatLonPointImpl p1 = new LatLonPointImpl(Double.valueOf(sv), Double.valueOf(wv));
    LatLonPointImpl p2 = new LatLonPointImpl(Double.valueOf(nv), Double.valueOf(ev));
    LatLonRect llr = new LatLonRect(p1, p2);

    return llr;
  }
예제 #7
0
 public List<String> getLocaleDirectories() throws JDOMException {
   List<Element> langAddedList = ((List<Element>) XPath.selectNodes(loopDoc, "//langAdded"));
   List<String> stringLocaleDirectories = new ArrayList<String>();
   List<Element> localeDirectories = new ArrayList<Element>();
   for (Element langAdded : langAddedList) {
     localeDirectories = langAdded.getChildren("language");
     for (Element localeDirectory : localeDirectories) {
       stringLocaleDirectories.add(localeDirectory.getValue());
     }
   }
   return stringLocaleDirectories;
 }
예제 #8
0
 static void loadNXParams(NXFrame nxFrame, Element elem) {
   if (elem == null) {
     return;
   }
   nxFrame.setVisible(false);
   Element e = elem.getChild("maxspeed");
   if (e != null) {
     try {
       nxFrame.setMaxSpeed(Float.valueOf(e.getValue()));
     } catch (NumberFormatException nfe) {
       log.error("NXWarrant MaxSpeed; " + nfe);
     }
   }
   e = elem.getChild("haltstart");
   if (e != null) {
     if (e.getValue().equals("yes")) {
       nxFrame.setStartHalt(true);
     } else {
       nxFrame.setStartHalt(false);
     }
   }
 }
예제 #9
0
  /**
   * get station object from parent element
   *
   * @param elem _more_
   * @return stationImpl
   */
  private Station readStation(Element elem) {
    // look for stations
    String name = elem.getAttributeValue("id");
    // latitude
    Element desc = elem.getChild("name");
    String descv = desc.getValue();
    Element lat = elem.getChild("latitude");
    String latv = lat.getValue();
    Element lon = elem.getChild("longitude");
    String lonv = lon.getValue();
    Element alt = elem.getChild("elevation");
    String altv = alt.getValue();

    StationImpl station =
        new StationImpl(
            name,
            descv,
            "",
            Double.parseDouble(latv),
            Double.parseDouble(lonv),
            Double.parseDouble(altv));

    return station;
  }
 /**
  * remove parts from this.nonSpecificParts if parts start a sentence in the description. for
  * example "Body ellipsoidal" suggests that the organism has one body, and it is not a unspecific
  * part of some other organ.
  *
  * @param text
  * @return
  */
 private String removeNonSpecificPartsIfFirstWord(Element description) {
   String result = this.nonSpecificParts;
   for (Element statement : description.getChildren("statement")) {
     String sentence = statement.getValue().toLowerCase().trim();
     if (sentence != null && sentence.matches("^[A-Z].*")) { // record parentorgan
       String word1 = sentence.toLowerCase();
       if (sentence.indexOf(" ") > 0)
         word1 = sentence.substring(0, sentence.indexOf(" ")).toLowerCase();
       result =
           this.nonSpecificParts
               .replaceFirst("(^|\\|)" + word1 + "(\\||$)", "|")
               .replaceFirst("(^\\||\\|$)", "");
     }
   }
   return result;
 }
  @Override
  public void transform(Document document) {
    for (Element description : this.descriptionXpath.evaluate(document)) {
      String nonSpecificParts = removeNonSpecificPartsIfFirstWord(description);

      String parentOrgan = null;
      Element biologicalEntityA = null;
      for (Element statement : description.getChildren("statement")) {
        List<Element> biologicalEntities = statement.getChildren("biological_entity");
        Element textElement = statement.getChild("text");
        String text = textElement.getValue();

        if (text != null && text.matches("^[A-Z].*")) { // record parentorgan
          if (!biologicalEntities.isEmpty()) {
            biologicalEntityA = biologicalEntities.get(0);
            // attach parent organ to other structures in this statement, return parentorgan used.
            parentOrgan =
                attachParentOrganToOtherBiologicalEntities(
                    document, description, statement, biologicalEntityA, "", nonSpecificParts);
          }
        } else {
          // sentences not starting with a capitalized structure names => those structures after ';'
          if (parentOrgan != null) {
            if (!biologicalEntities.isEmpty()) {
              // then apply parentorgan to the first structure
              biologicalEntityA = biologicalEntities.get(0);
              // apply parentorgan + localpo(struct) to other structures in the statement
              attachParentOrganToOtherBiologicalEntities(
                  document,
                  description,
                  statement,
                  biologicalEntityA,
                  parentOrgan,
                  nonSpecificParts);
              handlePartOfOrganOfOrgan(document, description, biologicalEntityA, parentOrgan);
            }
          }
        }
      }
    }
  }
 /**
  * This constructor is not intended for usage.
  *
  * @param xml An XML string
  * @throws JDOMException Is thrown when the xml string is invalid
  * @throws IOException Is thrown when the xml string is invalid
  */
 public LolStatus(String xml) throws JDOMException, IOException {
   outputter.setFormat(outputter.getFormat().setExpandEmptyElements(false));
   final SAXBuilder saxBuilder = new SAXBuilder();
   doc = saxBuilder.build(new StringReader(xml));
   for (final Element e : doc.getRootElement().getChildren()) {
     boolean found = false;
     for (final XMLProperty p : XMLProperty.values()) {
       if (p.name().equals(e.getName())) {
         found = true;
       }
     }
     if (!found) {
       System.err.println(
           "XMLProperty \""
               + e.getName()
               + "\" value: \""
               + e.getValue()
               + "\" not implemented yet!");
     }
   }
 }
예제 #13
0
  /**
   * get document from parent element
   *
   * @param elem _more_
   * @param ns _more_
   * @return _more_
   */
  private String readSelectDocument(Element elem, Namespace ns) {

    Element doc = elem.getChild("documentation", ns);
    return doc.getValue();
  }