예제 #1
0
  private void doit()
      throws JDOMException, IOException, SAXException, ParserConfigurationException,
          TransformerConfigurationException, TransformerException {
    Document CATALOG_DOCUMENT = FileIO.readDocumentFromLocalFile(CATALOG_FILE);
    List l =
        XPath.newInstance(
                "//resource[contains(@type,'exmaralda') and descendant::exmaralda-coma[@type='local']]")
            .selectNodes(CATALOG_DOCUMENT);
    for (Object o : l) {
      Element resourceElement = (Element) o;
      Element comaCorpusElement =
          (Element)
              XPath.newInstance("descendant::exmaralda-coma[@type='local']")
                  .selectSingleNode(resourceElement);
      String url = comaCorpusElement.getAttributeValue("url").substring(7);
      System.out.println("Processing " + url);

      COMACorpus comaCorpus = new COMACorpus();
      comaCorpus.readCorpus(new File(url), true);

      // resourceElement.removeChildren("annotation");
      HashSet<String> annotationNames = comaCorpus.getAnnotationNames();
      for (String annotationName : annotationNames) {
        if (XPath.newInstance("descendant::annotation[@category='" + annotationName + "']")
                .selectSingleNode(resourceElement)
            == null) {
          Element annotationElement = new Element("annotation");
          annotationElement.setAttribute("category", annotationName);
          int index =
              resourceElement.indexOf(
                  (Element)
                      XPath.newInstance("descendant::short-description[last()]")
                          .selectSingleNode(resourceElement));
          resourceElement.addContent(index + 1, annotationElement);
        }
      }
      FileIO.writeDocumentToLocalFile(CATALOG_FILE, CATALOG_DOCUMENT);
    }
  }
예제 #2
0
  private void processFiles()
      throws UnsupportedEncodingException, FileNotFoundException, IOException, JDOMException,
          SAXException, ParserConfigurationException, TransformerConfigurationException,
          TransformerException {
    StylesheetFactory sf = new StylesheetFactory(true);
    for (File inputFile : inputFiles) {
      System.out.println("Reading " + inputFile.getName());
      Document xmlDocument = FileIO.readDocumentFromLocalFile(inputFile.getAbsolutePath());

      Element recordingElement =
          (Element) XPath.newInstance("//recording").selectSingleNode(xmlDocument);
      String absoluteAudioPath = "";

      String path = determineAudio(old2new, inputFile);
      recordingElement.setAttribute("path", path);
      absoluteAudioPath = RelativePath.resolveRelativePath(path, inputFile.getAbsolutePath());
      double lengthInSeconds = -1.0;
      if (new File(absoluteAudioPath).exists()) {
        player.setSoundFile(absoluteAudioPath);
        lengthInSeconds = player.getTotalLength();
      }

      String nakedName = inputFile.getName().substring(0, inputFile.getName().indexOf("TRA."));
      XPath xp = XPath.newInstance("//audio-file[starts-with(@name,'" + nakedName + "')]");
      List l = xp.selectNodes(compareDocument);
      if (l != null) {
        Element compareElement = new Element("compare");
        compareElement.setAttribute("file", inputFile.getName());
        Element audioElement1 = new Element("audio");
        audioElement1.setAttribute("file", absoluteAudioPath);
        audioElement1.setAttribute("length", Double.toString(lengthInSeconds));
        compareElement.addContent(audioElement1);
        for (Object o : l) {
          Element e = (Element) o;
          Element audioElement2 = new Element("audio");
          // <audio-file name="HLD02BW2.WAV" path="W:\TOENE\HL\HLD\HLD02BW2.WAV"
          // seconds="129.62449645996094"length="02:09.62" bytes="11432924"/>
          audioElement2.setAttribute("file", e.getAttributeValue("path"));
          audioElement2.setAttribute("length", e.getAttributeValue("seconds"));
          compareElement.addContent(audioElement2);
        }
        logRoot.addContent(compareElement);
      }
    }

    writeLogToXMLFile(logDocument);
  }
예제 #3
0
  public CompareAudio(String[] args) throws JDOMException, IOException {
    inputDirectory = new File(args[0]);
    inputSuffix = args[1];
    getMappings(args[2]);

    compareDocument = FileIO.readDocumentFromLocalFile(args[3]);

    logFile = new File(args[4]);

    logRoot = new Element("compare-audio");
    logDocument = new Document(logRoot);

    inputFiles =
        inputDirectory.listFiles(
            new FilenameFilter() {
              @Override
              public boolean accept(File dir, String name) {
                return name.toUpperCase().endsWith(inputSuffix.toUpperCase());
              }
            });
  }