Package org.apache.xml.serializer

Examples of org.apache.xml.serializer.Serializer


  @Test
  public void testBuildDisjunctiveLF() throws Exception {
    Document paraphrases = documentBuilder.parse(paraphrasesFile);
   
    Serializer s = SerializerFactory.getSerializer(OUTPUT_PROPERTIES);
    s.setOutputFormat(OUTPUT_PROPERTIES);
    s.setWriter(new BufferedWriter(new FileWriter(outputFile)));
   
    Disjunctivizer disj = null;
    NodeList paras = paraphrases.getElementsByTagName("paraphrase");
    Document out = documentBuilder.newDocument();
    Element dlfsElement = out.createElement("dlfs");
    out.appendChild(dlfsElement);
   
    for(int i = 0; i < paras.getLength(); i++) {
      Element para = (Element)paras.item(i);
      Integer id = Integer.parseInt(para.getAttribute("id"));
     
      Element first = (Element)para.getElementsByTagName("first").item(0),
          second = (Element)para.getElementsByTagName("second").item(0);
     
      Set<Mapping> ms = new LinkedHashSet<Mapping>();
      NodeList als = para.getElementsByTagName("alignments");
      for(int j = 0; j < als.getLength(); j++) {
        Element al = (Element)als.item(j);
        if(al.getAttribute("source").equals("ANNOTATOR")) {
          NodeList as = al.getElementsByTagName("alignment");
          for(int k = 0; k < as.getLength(); k++) {
            Element a = (Element)as.item(k);
            ms.add(new Mapping(id, Integer.parseInt(a.getAttribute("first")),
                Integer.parseInt(a.getAttribute("second")),
                    Status.forAbbreviation(a.getAttribute("status"))));
          }
        }
      }
     
      Alignment a = new Alignment(new Phrase(id,
            Alignments.tokenize(first.getElementsByTagName("string").item(0).getTextContent())),
              new Phrase(id,
                Alignments.tokenize(second.getElementsByTagName("string").item(0).getTextContent())),
            ms);
     
      Element firstLF = (Element)first.getElementsByTagName("lf").item(0),
          secondLF = (Element)second.getElementsByTagName("lf").item(0);
     
      LFGraphDifference diff = (firstLF != null && secondLF != null)
          ? new LFGraphDifference(LFGraphFactory.newGraphFrom(firstLF),
              LFGraphFactory.newGraphFrom(secondLF), a)
          : null;
     
      for(PhrasePosition pos : PhrasePosition.values()) {
        Element str = out.createElement("string");
        str.setAttribute("number", Integer.toString(id));
        str.setAttribute("position", pos.name());
        str.setTextContent(Alignments.untokenize(a.get(pos)));
       
        dlfsElement.appendChild(str);
      }
     
      Element msEl = out.createElement("mappings");
      msEl.appendChild(out.createCDATASection(ms.toString()));
      dlfsElement.appendChild(msEl);
     
      if(diff == null) {
        dlfsElement.appendChild(out.createComment("missing LF!"));
      }
      else {
        if(disj == null) {
          disj = new Disjunctivizer(out);
        }
       
        Element dlf = disj.buildDisjunctiveLFFor(diff);
        dlfsElement.appendChild(dlf);
       
        assertEquals(dlf, disj.buildDisjunctiveLFFor(diff));
       
        dlfsElement.appendChild(disj.buildDisjunctiveLFFor(diff.reverse()));
       
        assertNotSame(dlf, disj.buildDisjunctiveLFFor(diff.reverse()));
      }
    }
   
    s.asDOMSerializer().serialize(out);
  }
View Full Code Here


     
      java.util.Properties xmlProps = OutputPropertiesFactory.getDefaultMethodProperties("xml");
      xmlProps.setProperty("indent", "yes");
      xmlProps.setProperty("standalone", "no");
        xmlProps.setProperty("{http://xml.apache.org/xalan}indent-amount", "2");
      Serializer serializer = SerializerFactory.getSerializer(xmlProps);             
      serializer.setOutputStream(new FileOutputStream(lexFile));
      xmlFilter.setContentHandler(serializer.asContentHandler());
      xmlFilter.parse(new InputSource(tempFile.getPath()));
    }
  }
View Full Code Here

     
      java.util.Properties xmlProps = OutputPropertiesFactory.getDefaultMethodProperties("xml");
      xmlProps.setProperty("indent", "yes");
      xmlProps.setProperty("standalone", "no");
      xmlProps.setProperty("{http://xml.apache.org/xalan}indent-amount", "2");
      Serializer serializer = SerializerFactory.getSerializer(xmlProps);
      serializer.setOutputStream(new FileOutputStream(rulesFile));


      XMLFilter xmlFilter = xmlFilter1;
      xmlFilter.setContentHandler(serializer.asContentHandler());
      xmlFilter.parse(new InputSource(tempFile.getPath()));
    }
   
    //Deleting the temporory lex file
    //lexiconTempFile.delete();
View Full Code Here

          .getDefaultMethodProperties("xml");
      xmlProps.setProperty("indent", "yes");
      xmlProps.setProperty("standalone", "no");
      xmlProps.setProperty("{http://xml.apache.org/xalan}indent-amount",
          "2");
      Serializer serializer = SerializerFactory.getSerializer(xmlProps);
      serializer.setOutputStream(new FileOutputStream(morphFile));
      //XMLFilter xmlFilter = xmlFilter2;
      //XMLFilter xmlFilter = xmlFilter3;

      xmlFilter.setContentHandler(serializer.asContentHandler());
      xmlFilter.parse(new InputSource(tempFile.getPath()));
    }

    //Deleting the temporary lex file
    //tempFile.delete();
View Full Code Here

TOP

Related Classes of org.apache.xml.serializer.Serializer

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.