Package uk.ac.cam.ch.wwmm.ptclib.xml

Examples of uk.ac.cam.ch.wwmm.ptclib.xml.XMLInserter


  public void addNe(String sid, String start, String end, String type) throws Exception {
    //System.out.printf("%s %s %s %s\n", sid, start, end, type);
    Element para = (Element)doc.query("//snippet[@id='" + sid + "']").get(0).getParent();
   
    XMLInserter xi = new XMLInserter(para, "a", "c");
       
    Element ne = new Element("ne");
    ne.addAttribute(new Attribute("type", type));
    xi.insertElement(ne, start, end);
    xi.deTagDocument();
    writeScrapBook();
  }
View Full Code Here


    Nodes n = para.query(".//ne");

    Element ne = (Element)n.get(Integer.parseInt(neid));
    XOMTools.removeElementPreservingText(ne);

    XMLInserter xi = new XMLInserter(para, "a", "c");   
    xi.insertElement(ne, start, end);
    xi.deTagDocument();
    writeScrapBook();   
  }
View Full Code Here

    for(int i=0;i<snippetNodes.size();i++) {
      try {
      Element snippet = (Element)snippetNodes.get(i);
      Element targetElem = (Element)XOMTools.getNodeAtXPoint(doc.getRootElement(), snippet.getAttributeValue("XPoint"));

      XMLInserter xi = new XMLInserter(targetElem, "a", "c");
     
      XMLSpanTagger xst = new XMLSpanTagger(snippet, "b");
      Nodes neNodes = snippet.query(".//ne");
      for(int j=0;j<neNodes.size();j++) {
        xi.insertTaggedElement((Element)neNodes.get(j));
      }
      xst.deTagDocument();
      xi.deTagDocument();
      } catch (Exception e) {
       
      }
    }
  }
View Full Code Here

    Nodes p1n = doc1.query("//P");
    Nodes p2n = doc2.query("//P");
    for(int i=0;i<p1n.size();i++) {
      Element p1 = (Element)p1n.get(i);
      Element p2 = (Element)p2n.get(i);
      XMLInserter xi = new XMLInserter(p1, "a", "b");
      XMLSpanTagger.tagUpDocument(p2, "b");
      xi.incorporateElementsFromRetaggedDocument(p2, "b");
      xi.deTagDocument();
      System.out.println(p1.toXML());

      Nodes en = p1.query("ne/ne");
      for(int j=0;j<en.size();j++) {
        XOMTools.removeElementPreservingText((Element)en.get(j));
View Full Code Here

      }
      Element p = new Element("P");
      p.addAttribute(new Attribute("ID", id));
      p.appendChild(sentencesById.get(id));
      if(genesById.containsKey(id)) {
        XMLInserter xi = new XMLInserter(p, "a", "b");
        for(Gene g : genesById.get(id)) {
          Element ne = new Element("ne");
          ne.addAttribute(new Attribute("type", "GENE"));
          ne.appendChild(g.contents);
          xi.insertElement(ne, g.start, g.end);
        }
        xi.deTagDocument();
      }
      sentenceElems.add(p);
      //System.out.println(p.toXML());
    }
   
View Full Code Here

                // System.out.printf("%s %s %s %s\n", sid, start, end, type);
                Element para = (Element) doc.query("//snippet[@id='" + sid + 
"']").get(
                                0).getParent();

                XMLInserter xi = new XMLInserter(para, "a", "c");

                Element ne = new Element("ne");
                ne.addAttribute(new Attribute("type", type));
                xi.insertElement(ne, start, end);
                xi.deTagDocument();
                writeScrapBook();
        }
View Full Code Here

                Nodes n = para.query(".//ne");

                Element ne = (Element) n.get(Integer.parseInt(neid));
                XOMTools.removeElementPreservingText(ne);

                XMLInserter xi = new XMLInserter(para, "a", "c");
                xi.insertElement(ne, start, end);
                xi.deTagDocument();
                writeScrapBook();
        }
View Full Code Here

    for(int i=0;i<snippetNodes.size();i++) {
      try {
      Element snippet = (Element)snippetNodes.get(i);
      Element targetElem = (Element)XOMTools.getNodeAtXPoint(doc.getRootElement(), snippet.getAttributeValue("XPoint"));

      XMLInserter xi = new XMLInserter(targetElem, "a", "c");
     
      XMLSpanTagger xst = new XMLSpanTagger(snippet, "b");
      Nodes neNodes = snippet.query(".//ne");
      for(int j=0;j<neNodes.size();j++) {
        xi.insertTaggedElement((Element)neNodes.get(j));
      }
      xst.deTagDocument();
      xi.deTagDocument();
      } catch (Exception e) {
       
      }
    }
  }
View Full Code Here

        " +++*<w>**+++</w> +++***+++ </a>", "/localhost").getRootElement();
    String expectedOut = ("<a> <b /><c /> <c /><b /> <b><c /></b> <c><b /></c> \n" +
        " <b><c>_</c></b> <b /><c>_</c> <c><b />_</c> <b>_<c /></b> <b>_</b><c /> \n" +
        " +++<z>***</z>+++ +++*<d>*</d>*+++ +++<d><x>***</x></d>+++ +++<d>**</d>*+++ +++*<d>**</d>+++ \n" +
        " +++*<d /><w>**+++</w> +++*<d><e>*</e></d>*+++ </a>");
    XMLInserter xi = new XMLInserter(baselineXMLCopy, "a", "c");
    XMLSpanTagger.tagUpDocument(newXML, "b");
    xi.incorporateElementsFromRetaggedDocument(newXML, "b");
   
    xi.deTagDocument();   
    assertEquals("Insertion goes in OK", expectedOut, baselineXMLCopy.toXML());
  }
View Full Code Here

  public static Document safToInline(Document safDoc, Document plainDoc, Document ontoDoc, boolean brittle) throws Exception {
    Document resultsDoc = new Document((Element)XOMTools.safeCopy(ontoDoc.getRootElement()));
    plainDoc = new Document((Element)XOMTools.safeCopy(plainDoc.getRootElement()));
   
    StandoffTable st = new StandoffTable(plainDoc.getRootElement());
    XMLInserter xi = new XMLInserter(resultsDoc.getRootElement(), "a", "c");
    new XMLSpanTagger(plainDoc.getRootElement(), "b");
   
    Nodes annots = safDoc.query("//annot");
    for(int i=0;i<annots.size();i++) {
      //if(true) continue;
      Element annot = (Element)annots.get(i);
     
      String blocked = SafTools.getSlotValue(annot, "blocked");
      if("true".equals(blocked)) continue;
     
      Element ne = new Element("ne");
     
      String type = SafTools.getSlotValue(annot, "type");
      if(null == type) continue;
      if("dataSection".equals(type)) ne.setLocalName("datasection");
     
      if(annot.getAttribute("id") != null) ne.addAttribute(new Attribute("id", annot.getAttributeValue("id")));
     
      Elements slots = annot.getChildElements("slot");
      for(int j=0;j<slots.size();j++) {
        String slotName = slots.get(j).getAttributeValue("name");
        //if(slotName.equals("surface")) continue;
        ne.addAttribute(new Attribute(slotName, slots.get(j).getValue()));
      }
      int startOffset; int endOffset;
      try {
        startOffset = st.getOffsetAtXPoint(annot.getAttributeValue("from"));
        endOffset = st.getOffsetAtXPoint(annot.getAttributeValue("to"));
      } catch (Exception e) {
        if(brittle)  {
          e.printStackTrace();
          System.err.println(annot.getAttributeValue("from"));
          System.err.println(annot.getAttributeValue("to"));
          throw e;
          }
        else {
          System.err.println("Warning: could not inline a named entity: ");
          System.err.println("from: " + annot.getAttributeValue("from"));
          System.err.println("to: " + annot.getAttributeValue("to"));
          System.err.println(annot.query("slot[@name='surface']").get(0).getValue());
          continue;
        }
      }
      if(startOffset < 0 || endOffset < 0 || startOffset > endOffset) {
        if(brittle) {
        throw new Exception ("Bad offsets: " + annot.getAttributeValue("from") + " " + Integer.toString(startOffset) + " " +
            annot.getAttributeValue("to") + " " + Integer.toString(endOffset));
        } else {
          System.err.println("Warning: could not inline a named entity: ");
          System.err.println("from: " + annot.getAttributeValue("from"));
          System.err.println("to: " + annot.getAttributeValue("to"));
          System.err.println(annot.query("slot[@name='surface']").get(0).getValue());
          continue;         
        }
      }
      try {
        xi.insertElement(ne, startOffset, endOffset);
      } catch (Exception e) {
        if(brittle) {
        System.err.println(ne.toXML());
        System.err.println(annot.getAttributeValue("from"));
        System.err.println(annot.getAttributeValue("to"));
        System.err.println(startOffset);
        System.err.println(endOffset);
        throw e;
        } else {
          System.err.println("Warning: could not inline a named entity: ");
          System.err.println("from: " + annot.getAttributeValue("from"));
          System.err.println("to: " + annot.getAttributeValue("to"));
          Nodes n = annot.query("slot[@name='surface']");
          if(n.size() > 0) System.err.println(n.get(0).getValue());
          continue;         
        }
      }
    }
    xi.deTagDocument();
   
    Nodes n = safDoc.query("//cmlPile");
    if(n.size() > 0) {
      resultsDoc.getRootElement().appendChild(n.get(0).copy());
    }
View Full Code Here

TOP

Related Classes of uk.ac.cam.ch.wwmm.ptclib.xml.XMLInserter

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.