/**
   * 1) Performs re-ranking using a linear function, which takes into account only three features:
   * newRank = 1 * oldRank + 10 * underconstrained_query + 10 * incosistent_tense; <br>
   * 2) Takes the hypothesis which is smallest in (new) rank as the best one. <br>
   * 3) Computes the semantic error rate (SER) as follows: -- a recognition is considered as
   * semantically correct if the dialogue move representation it produces is both a) non-null and b)
   * the same as the one that would have been produced from a perfect recognition result. -- if
   * dialogue move is not the same: then counts the number of deletions/insertions required in order
   * to obtain the perfect dialogue move.
   *
   * @deprecated Use instead the linear re-ranking with more than 3 feat and SER manually defined
   *     (available in xml file)
   * @param xmlFileName - input xml file containing both the n-best hypothesis and the reference
   *     transcription.
   * @return
   * @throws Exception
   */
  public float[] getER4LinearReranking3Feat(String xmlFileName) throws Exception {
    // read the xml file in order to get the utterance transcripts
    try {
      Document d =
          new org.jdom.input.SAXBuilder().build(new File(xmlFileName)); // PARSE THE XML FILE
      java.util.List nbestList = d.getRootElement().getChildren("nbest_data");
      float[] serArray = new float[nbestList.size()];
      int noUtt = 0;
      int minNewRankID = 1;

      for (int i = 0; i < nbestList.size(); i++) {
        Element nbestElem = (Element) nbestList.get(i);
        noUtt++;

        // In order to COMPUTE SEMANTIC ERROR RATE (ser),
        // get the dialogue_move feature value for the correct transcription
        // dialogue_move
        Element dmElem = nbestElem.getChild("dialogue_move");
        String refDM = "";
        if (dmElem != null) if (!dmElem.getValue().equalsIgnoreCase("")) refDM = dmElem.getValue();

        // In the xml tree: find hyp_transcription,
        // i.e. the transcription corresponding to the 1-rank predicted hypothesis
        java.util.List recList = nbestElem.getChildren("recognition");

        // PERFORM LINEAR RE-RANKING
        int minNewRank = 100;
        for (int j = 1; j < recList.size(); j++) {
          Element recElem = (Element) recList.get(j);
          int rank = new Integer(recElem.getChild("rank").getValue()).intValue();
          int uq = new Integer(recElem.getChild("underconstrained_query").getValue()).intValue();
          int it = new Integer(recElem.getChild("inconsistent_tense").getValue()).intValue();

          int newRank = rank + 10 * uq + 10 * it;
          if (newRank < minNewRank) {
            minNewRank = newRank;
            minNewRankID = j;
          }
        }

        Element recElem = (Element) recList.get(minNewRankID);
        Element dm4recElem = recElem.getChild("dialogue_move");
        String dm4rec = "";
        if (dm4recElem != null)
          if (!dm4recElem.getValue().equalsIgnoreCase("")) dm4rec = dm4recElem.getValue();

        WordErrorRate wer = new WordErrorRate(refDM, dm4rec, this.wordDeliminator);
        serArray[i] = wer.computeNumerator();
      }

      return serArray;
    } catch (IOException eIO) {
      eIO.printStackTrace();
    } catch (JDOMException eJDOM) {
      eJDOM.printStackTrace();
    }
    return null;
  }
 /**
  * This method checks that returning a remote objects works alright.
  *
  * @param elems A group of elements.
  * @return The minimum-valued element.
  */
 public Element minElem(Element[] elems) {
   if (elems == null) throw new IllegalArgumentException("Elems cannot be null!");
   Element curMin = null;
   int curMinValue = Integer.MAX_VALUE;
   for (int i = 0; i < elems.length; i++) {
     Element curElem = elems[i];
     if (curElem.getValue() < curMinValue) {
       curMin = curElem;
       curMinValue = curMin.getValue();
     }
   }
   return curMin;
 }
Esempio n. 3
0
 public String peek() throws EmptyStackException { // tylko pokaz
   try {
     if (_size == 0) throw new EmptyStackException();
   } catch (EmptyStackException e) {
     e.komunikat();
   }
   Element e = _first;
   while (e.getNext() != null) {
     e = e.getNext();
   }
   System.out.println("\nOstatni element ze stosu: " + e.getValue());
   pokaz();
   return e.getValue();
 }
Esempio n. 4
0
 public T get(Key key) {
   Element e = map.get(key);
   if (e == null) {
     return null;
   }
   return (T) e.getValue();
 }
Esempio n. 5
0
  private void compose(String path, Element element) throws IOException {
    Property p =
        element.hasElementProperty() ? element.getElementProperty() : element.getProperty();
    String en = getFormalName(element);

    if (element.fhirType().equals("xhtml")) {
      json.name(en);
      json.value(element.getValue());
    } else if (element.hasChildren() || element.hasComments() || element.hasValue()) {
      open(en);
      if (element.getProperty().isResource()) {
        prop("@type", "fhir:" + element.getType());
        //        element = element.getChildren().get(0);
      }
      if (element.isPrimitive() || isPrimitive(element.getType())) {
        if (element.hasValue()) primitiveValue(element);
      }

      Set<String> done = new HashSet<String>();
      for (Element child : element.getChildren()) {
        compose(path + "." + element.getName(), element, done, child);
      }
      if ("Coding".equals(element.getType())) decorateCoding(element);
      if ("CodeableConcept".equals(element.getType())) decorateCodeableConcept(element);
      if ("Reference".equals(element.getType())) decorateReference(element);

      close();
    }
  }
Esempio n. 6
0
 private void primitiveValue(Element item) throws IOException {
   String type = item.getType();
   if (Utilities.existsInList(type, "date", "dateTime", "instant")) {
     String v = item.getValue();
     if (v.length() > 10) {
       int i = v.substring(10).indexOf("-");
       if (i == -1) i = v.substring(10).indexOf("+");
       v = i == -1 ? v : v.substring(0, 10 + i);
     }
     if (v.length() > 10) json.name("dateTime");
     else if (v.length() == 10) json.name("date");
     else if (v.length() == 7) json.name("gYearMonth");
     else if (v.length() == 4) json.name("gYear");
     json.value(item.getValue());
   } else if (Utilities.existsInList(type, "boolean")) {
     json.name("boolean");
     json.value(item.getValue().equals("true") ? new Boolean(true) : new Boolean(false));
   } else if (Utilities.existsInList(type, "integer", "unsignedInt", "positiveInt")) {
     json.name("integer");
     json.value(new Integer(item.getValue()));
   } else if (Utilities.existsInList(type, "decimal")) {
     json.name("decimal");
     json.value(item.getValue());
   } else if (Utilities.existsInList(type, "base64Binary")) {
     json.name("binary");
     json.value(item.getValue());
   } else {
     json.name("value");
     json.value(item.getValue());
   }
 }
Esempio n. 7
0
    @Override
    public boolean equals(Object o) {
      if (o == null) return false;

      if (o instanceof Element == false) return false;

      Element other = (Element) o;
      return other.getValue().equals(this.getValue());
    }
Esempio n. 8
0
 public void push(String value) { // wstaw do kolejki
   if (_first.getValue() == null) _first.setValue(value);
   else {
     Element e = _first;
     while (e.getNext() != null) e = e.getNext();
     e.setNext(new Element(value));
   }
   _size++;
 }
Esempio n. 9
0
 public void pokaz() {
   System.out.println("");
   Element e = _first;
   int i = 1;
   while (e != null) {
     System.out.println(i + ". " + e.getValue());
     i++;
     e = e.getNext();
   }
 }
Esempio n. 10
0
 public Collection<T> getAll() {
   Collection<T> values = new ArrayList<>();
   Collection coll = map.values();
   for (Object o : coll) {
     Element e = (Element) o;
     Object v = e.getValue();
     if (v != null) {
       values.add((T) v);
     }
   }
   return values;
 }
Esempio n. 11
0
 public String pop() throws EmptyStackException { // pobierz i wywal
   try {
     if (_size == 0) throw new EmptyStackException();
   } catch (EmptyStackException e) {
     e.komunikat();
   }
   Element e = _first;
   while (e.getNext().getNext() != null) {
     e = e.getNext();
   }
   System.out.println("\nZdjecie ostatniego elementu ze stosu: " + e.getNext().getValue());
   e.setNext(null);
   _size--;
   pokaz();
   return e.getValue();
 }
Esempio n. 12
0
  /**
   * Compute the best semantic error rate that can be achieved starting from n-best hypothesis.
   *
   * @param xmlFileName
   * @return a list of error rates corresponding to each utterance
   * @throws Exception
   */
  public float[] getBestERCanBeAchieved(String xmlFileName) throws Exception {
    // read the xml file in order to get the utterance transcripts
    try {
      Document d =
          new org.jdom.input.SAXBuilder().build(new File(xmlFileName)); // PARSE THE XML FILE
      java.util.List nbestList = d.getRootElement().getChildren("nbest_data");
      float[] serArray = new float[nbestList.size()];
      int noUtt = 0;
      for (int i = 0; i < nbestList.size(); i++) {
        Element nbestElem = (Element) nbestList.get(i);
        noUtt++;

        // In order to COMPUTE SEMANTIC ERROR RATE (SER)

        java.util.List recList = nbestElem.getChildren("recognition");

        float bestSER = 10000;
        // (start with k=1 since we skip first value in recList which corresponds to the correct
        // transcription)
        for (int k = 1; k < recList.size(); k++) {
          Element recElem = (Element) recList.get(k);

          Element semCorrectElem = recElem.getChild("semantically_correct");
          String semCorrect = semCorrectElem.getValue();
          int ser;
          if (semCorrect.equalsIgnoreCase("good")) ser = 0;
          else ser = 1;

          if (bestSER > ser) {
            bestSER = ser;
          }
        } // end for k
        serArray[i] = bestSER;
      }
      return serArray;
    } catch (IOException eIO) {
      eIO.printStackTrace();
    } catch (JDOMException eJDOM) {
      eJDOM.printStackTrace();
    }
    return null;
  }
Esempio n. 13
0
  /**
   * Gets the SER for a naive algorithm which does random re-ranking.
   *
   * @param xmlFileName
   * @param svmPredFileName
   * @return
   * @throws Exception
   */
  public float[] getER4RandomHyp(String xmlFileName) throws Exception {
    // read the xml file in order to get the utterance transcripts
    try {

      Document d =
          new org.jdom.input.SAXBuilder().build(new File(xmlFileName)); // PARSE THE XML FILE
      java.util.List nbestList = d.getRootElement().getChildren("nbest_data");
      float[] serArray = new float[nbestList.size()];
      int noUtt = 0;
      java.util.Random rand = new java.util.Random();

      for (int i = 0; i < nbestList.size(); i++) {
        Element nbestElem = (Element) nbestList.get(i);
        noUtt++;
        java.util.List recList = nbestElem.getChildren("recognition");

        int bestRankIdx = rand.nextInt(recList.size() - 1) + 1;

        // System.out.println("best rank = " + bestRankIdx);
        if (recList.size() < bestRankIdx)
          System.out.println("Less than " + bestRankIdx + " recognitions !!! ");

        Element recElem = (Element) recList.get(bestRankIdx);

        Element semCorrectElem = recElem.getChild("semantically_correct");
        String semCorrect = semCorrectElem.getValue();
        if (semCorrect.equalsIgnoreCase("good")) serArray[i] = 0;
        else serArray[i] = 1;
      }
      return serArray;
    } catch (IOException eIO) {
      eIO.printStackTrace();
    } catch (JDOMException eJDOM) {
      eJDOM.printStackTrace();
    } catch (NullPointerException nullE) {
      nullE.printStackTrace();
    }
    return null;
  }
Esempio n. 14
0
  public void testXmlSerializer() throws Exception {
    Format root = new DataFormat("root");
    Format person = root.addChild("Person", Format.Form.STRUCT);
    person.setProperty("test1", new Value("prop1"));
    person.setProperty("test2", new Value(119));
    person.setProperty("test3", new Value(true));
    person.setProperty("test4", new Value(3.1415926f));
    person.addChild("name", Format.Form.FIELD, Type.STRING);
    Format asset = person.addChild("asset", Format.Form.ARRAYOFSTRUCT);
    asset.addChild("test", Format.Form.ARRAYOFFIELD, Type.STRING);
    asset.addChild("name", Format.Form.FIELD, Type.STRING);
    asset.addChild("price", Format.Form.FIELD, Type.FLOAT);
    Format name =
        asset
            .addChild("vendor", Format.Form.STRUCT)
            .addChild("name", Format.Form.FIELD, Type.STRING);

    Element personData = new DataElement(person);
    Element nameData = personData.addChild("name");
    nameData.setValue("James wang");
    assertEquals("James wang", nameData.getValue().getString());
    Element assetData = personData.addChild("asset");
    Element assetDataItem = assetData.addArrayItem();
    assetDataItem.addChild("test").addArrayItem().setValue("test collection default index");
    assetDataItem.addChild("name").setValue("Mac air book");
    assetDataItem.addChild("price").setValue(12000.05f);
    assetDataItem.addChild("vendor").addChild("name").setValue("Apple");
    assetDataItem = assetData.addArrayItem();
    assetDataItem.addChild("name").setValue("HP computer");
    assetDataItem.addChild("price").setValue(15000.05f);
    assetDataItem.addChild("vendor").addChild("name").setValue("HP");

    ElementXmlSerializer serializer = new ElementXmlSerializer(personData, true);
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    serializer.write(baos);
    System.out.println(baos.toString());
  }
Esempio n. 15
0
 public int compareTo(Element arg0) {
   return this.getValue().compareTo(arg0.getValue());
 }
Esempio n. 16
0
  /**
   * Gets the SER for linear re-ranking. Two main steps are performed: * 1) Performs re-ranking
   * using a linear function, which takes into account ..., i.e. newRank = ... <br>
   * 2) Takes the hypothesis which is smallest in (new) rank as the best one. <br>
   * 3) Computes the semantic error rate (SER) as defined in the "semantically_correct" tag
   */
  public float[] getER4LinearReranking(String xmlFileName) throws Exception {
    // read the xml file in order to get the utterance transcripts
    try {

      Document d =
          new org.jdom.input.SAXBuilder().build(new File(xmlFileName)); // PARSE THE XML FILE
      java.util.List nbestList = d.getRootElement().getChildren("nbest_data");
      float[] serArray = new float[nbestList.size()];
      int noUtt = 0;
      int minNewRankID = 1;

      for (int i = 0; i < nbestList.size(); i++) {
        Element nbestElem = (Element) nbestList.get(i);
        noUtt++;
        java.util.List recList = nbestElem.getChildren("recognition");

        ///////////////////////////////////////////
        int minNewRank = 100;
        for (int j = 1; j < recList.size(); j++) {
          Element recElem = (Element) recList.get(j);
          int rank = new Integer(recElem.getChild("rank").getValue()).intValue();
          int no_dialogue_move =
              new Integer(recElem.getChild("no_dialogue_move").getValue()).intValue();
          int underconstrained_query =
              new Integer(recElem.getChild("underconstrained_query").getValue()).intValue();
          int non_indefinite_existential =
              new Integer(recElem.getChild("non_indefinite_existential").getValue()).intValue();
          int non_show_imperative =
              new Integer(recElem.getChild("non_show_imperative").getValue()).intValue();
          int indefinite_meeting_and_meeting_referent =
              new Integer(recElem.getChild("indefinite_meeting_and_meeting_referent").getValue())
                  .intValue();

          /*
          					% 1) Place in the N-best list - lower number is better
          					feature_weight(rank, -1).
          					% 2) Strongly penalise hypotheses that produce no dialogue move
          					feature_weight(no_dialogue_move, -50).
          					% 3) Penalise queries with no contentful constraints
          					feature_weight(underconstrained_query, -10).
          					% 4) Penalise existentials which aren't indefinite, e.g. "is there the meeting next week"
          					feature_weight(non_indefinite_existential, -10).
          					% 5) Strongly penalise imperatives where the main verb isn't "show" or something similar
          					feature_weight(non_show_imperative, -50).
          					% 6) Disprefer combination of indefinite mention of meeting + available meeting referent
          					feature_weight(indefinite_meeting_and_meeting_referent, -2).
          */
          int newRank =
              rank
                  + 50 * no_dialogue_move
                  + 10 * underconstrained_query
                  + 10 * non_indefinite_existential
                  + 50 * non_show_imperative
                  + 2 * indefinite_meeting_and_meeting_referent;
          if (newRank < minNewRank) {
            minNewRank = newRank;
            minNewRankID = j;
          }
        }

        Element recElem = (Element) recList.get(minNewRankID);

        //////////////////////////////////////////
        // System.out.println("best rank = " + minNewRankID);
        if (recList.size() < minNewRankID)
          System.out.println("Less than " + minNewRankID + " recognitions !!! ");

        Element semCorrectElem = recElem.getChild("semantically_correct");
        String semCorrect = semCorrectElem.getValue();
        if (semCorrect.equalsIgnoreCase("good")) serArray[i] = 0;
        else serArray[i] = 1;
      }
      return serArray;
    } catch (IOException eIO) {
      eIO.printStackTrace();
    } catch (JDOMException eJDOM) {
      eJDOM.printStackTrace();
    } catch (NullPointerException nullE) {
      nullE.printStackTrace();
    }
    return null;
  }
 private static List<CoreMap> toTimexCoreMaps(Element docElem, CoreMap originalDocument) {
   // --Collect Token Offsets
   HashMap<Integer, Integer> beginMap = new HashMap<Integer, Integer>();
   HashMap<Integer, Integer> endMap = new HashMap<Integer, Integer>();
   boolean haveTokenOffsets = true;
   for (CoreMap sent : originalDocument.get(CoreAnnotations.SentencesAnnotation.class)) {
     for (CoreLabel token : sent.get(CoreAnnotations.TokensAnnotation.class)) {
       Integer tokBegin = token.get(CoreAnnotations.TokenBeginAnnotation.class);
       Integer tokEnd = token.get(CoreAnnotations.TokenEndAnnotation.class);
       if (tokBegin == null || tokEnd == null) {
         haveTokenOffsets = false;
       }
       int charBegin = token.get(CoreAnnotations.CharacterOffsetBeginAnnotation.class);
       int charEnd = token.get(CoreAnnotations.CharacterOffsetEndAnnotation.class);
       beginMap.put(charBegin, tokBegin);
       endMap.put(charEnd, tokEnd);
     }
   }
   // --Set Timexes
   List<CoreMap> timexMaps = new ArrayList<CoreMap>();
   int offset = 0;
   Element textElem = docElem.getFirstChildElement("text");
   for (int i = 0; i < textElem.getChildCount(); i++) {
     Node content = textElem.getChild(i);
     if (content instanceof Text) {
       Text text = (Text) content;
       offset += text.getValue().length();
     } else if (content instanceof Element) {
       Element child = (Element) content;
       if (child.getLocalName().equals("TIMEX3")) {
         Timex timex = new Timex(child);
         if (child.getChildCount() != 1) {
           throw new RuntimeException("TIMEX3 should only contain text " + child);
         }
         String timexText = child.getValue();
         CoreMap timexMap = new ArrayCoreMap();
         // (timex)
         timexMap.set(TimexAnnotation.class, timex);
         // (text)
         timexMap.set(CoreAnnotations.TextAnnotation.class, timexText);
         // (characters)
         int charBegin = offset;
         timexMap.set(CoreAnnotations.CharacterOffsetBeginAnnotation.class, charBegin);
         offset += timexText.length();
         int charEnd = offset;
         timexMap.set(CoreAnnotations.CharacterOffsetEndAnnotation.class, charEnd);
         // (tokens)
         if (haveTokenOffsets) {
           Integer tokBegin = beginMap.get(charBegin);
           int searchStep = 1; // if no exact match, search around the character offset
           while (tokBegin == null) {
             tokBegin = beginMap.get(charBegin - searchStep);
             if (tokBegin == null) {
               tokBegin = beginMap.get(charBegin + searchStep);
             }
             searchStep += 1;
           }
           searchStep = 1;
           Integer tokEnd = endMap.get(charEnd);
           while (tokEnd == null) {
             tokEnd = endMap.get(charEnd - searchStep);
             if (tokEnd == null) {
               tokEnd = endMap.get(charEnd + searchStep);
             }
             searchStep += 1;
           }
           timexMap.set(CoreAnnotations.TokenBeginAnnotation.class, tokBegin);
           timexMap.set(CoreAnnotations.TokenEndAnnotation.class, tokEnd);
         }
         // (add)
         timexMaps.add(timexMap);
       } else {
         throw new RuntimeException("unexpected element " + child);
       }
     } else {
       throw new RuntimeException("unexpected content " + content);
     }
   }
   return timexMaps;
 }
Esempio n. 18
0
  public static Relatorio parse(java.io.File checkStyleResultsFile, String classe, String programa)
      throws SQLException, ClassNotFoundException {
    conn = conectar();
    if (!checkStyleResultsFile.exists()) {
      return null;
    }

    Relatorio relatorio = new Relatorio();
    SAXBuilder builder = new SAXBuilder();
    String sql5 = "select * from ferramenta where nome='pmd'";

    Statement stmt = conn.createStatement();
    ResultSet rs3 = stmt.executeQuery(sql5);

    /* Inserindo classe se não existir */

    if (!rs3.next()) {
      String sql6 =
          "insert into ferramenta "
              + "(id,"
              + "descricao, "
              + "linguagem, "
              + "nome,"
              + "tipo,"
              + "versao) "
              + "values (?,?,?,?,?,?)";
      PreparedStatement stat3 = conn.prepareStatement(sql6);
      stat3.setString(1, "PM0006");
      stat3.setString(2, "");
      stat3.setString(3, "java");
      stat3.setString(4, "pmd");
      stat3.setString(5, "codigo fonte");
      stat3.setString(6, "");
      stat3.executeUpdate();
    }

    try {
      Document document = builder.build(checkStyleResultsFile);
      Element rootNode = document.getRootElement();

      List filesXml = rootNode.getChildren("file");
      List<Arquivo> files = new ArrayList<Arquivo>();
      for (int i = 0; i < filesXml.size(); i++) {
        Element fileNode = (Element) filesXml.get(i);
        String name = fileNode.getAttributeValue("name");

        List errorsXml = fileNode.getChildren("violation");
        List<Error> errors = new ArrayList<Error>();
        for (int j = 0; j < errorsXml.size(); j++) {
          Element errorNode = (Element) errorsXml.get(j);
          String beginline = errorNode.getAttributeValue("beginline");
          String endline = errorNode.getAttributeValue("endline");
          String begincolumn = errorNode.getAttributeValue("begincolumn");
          String endcolumn = errorNode.getAttributeValue("endcolumn");
          String classe2 = errorNode.getAttributeValue("class");
          String externalinfourl = errorNode.getAttributeValue("externalInfoUrl");
          String rules = errorNode.getAttributeValue("rule");
          String ruleset = errorNode.getAttributeValue("ruleset");
          String priority = errorNode.getAttributeValue("priority");

          String sql =
              "insert into warning"
                  + "(tool, "
                  + "nameprogram, "
                  + "nameclass, "
                  + "namemethod, "
                  + "beginline, "
                  + "endline,"
                  + "begincolumn, "
                  + "endcolumn,"
                  + "typewarning,"
                  + "description,"
                  + "priority,"
                  + "externalinfourl,"
                  + "ruleset ) values (?,?,?,?,?,?,?,?,?,?,?,?,?)";
          PreparedStatement pstm = conn.prepareStatement(sql);
          pstm.setString(1, "PM0006");
          pstm.setString(2, programa);
          String aux = classe.replace("source-", "");
          String aux3 = aux.replace("-", ".");
          String aux4 = aux3.replace(".java", "");
          pstm.setString(3, aux4);
          pstm.setString(4, "");
          pstm.setInt(5, Integer.parseInt(beginline));
          pstm.setInt(6, Integer.parseInt(endline));
          pstm.setInt(7, Integer.parseInt(begincolumn));
          pstm.setInt(8, Integer.parseInt(endcolumn));
          pstm.setString(9, rules);

          String aux2 = "" + errorNode.getValue();
          File arquivo = new File("/home/vr/Dropbox/WarningsFix/tmp/buffer.txt");
          FileWriter fw = new FileWriter(arquivo, true);
          BufferedWriter bw = new BufferedWriter(fw);
          bw.write(aux2);
          bw.close();
          fw.close();
          // faz a leitura do arquivo

          try {
            FileReader fr = new FileReader(arquivo);

            BufferedReader br = new BufferedReader(fr);

            // equanto houver mais linhas
            String linha;
            while ((linha = br.readLine()) != null) { // lê a proxima linha
              pstm.setString(10, linha);
            }

            br.close();
            fr.close();

          } catch (IOException ex) {
            ex.printStackTrace();
          }
          arquivo.delete();
          pstm.setInt(11, Integer.parseInt(priority));
          pstm.setString(12, externalinfourl);
          pstm.setString(13, ruleset);
          pstm.executeUpdate();

          System.out.println(
              " "
                  + beginline
                  + " "
                  + endline
                  + " "
                  + begincolumn
                  + " "
                  + endcolumn
                  + " "
                  + classe2
                  + " "
                  + programa
                  + " "
                  + externalinfourl
                  + " "
                  + priority
                  + " "
                  + ruleset
                  + " "
                  + rules);
          errors.add(
              new Error(
                  beginline,
                  endline,
                  begincolumn,
                  endcolumn,
                  classe2,
                  externalinfourl,
                  priority,
                  ruleset,
                  rules));
        }

        files.add(new Arquivo(name, errors));
      }
      relatorio.setFiles(files);

    } catch (JDOMException e) {
      e.printStackTrace(); // To change body of catch statement use Arquivo | Settings | Arquivo
      // Templates.
    } catch (IOException e) {
      e.printStackTrace(); // To change body of catch statement use Arquivo | Settings | Arquivo
      // Templates.
    }
    desconectar(conn);
    return relatorio;
  }
Esempio n. 19
0
  /**
   * Gets the SER for re-ranking predicted by the machine learning technique.
   *
   * @param xmlFileName the XML file name containing the reference data (i.e. the human utterance
   *     transcription).
   * @param svmPredFileName - file name of the hypothetised data (i.e. the re-estimated recognition
   *     )
   * @return Semantic Error Rate
   * @throws Exception
   */
  public float[] getER4Predicted(String xmlFileName, String svmPredFileName) throws Exception {
    // read the xml file in order to get the utterance transcripts
    try {
      BufferedReader br = getBufferedReader(svmPredFileName);
      Document d =
          new org.jdom.input.SAXBuilder().build(new File(xmlFileName)); // PARSE THE XML FILE
      java.util.List nbestList = d.getRootElement().getChildren("nbest_data");
      float[] serArray = new float[nbestList.size()];
      int noUtt = 0;
      for (int i = 0; i < nbestList.size(); i++) {
        Element nbestElem = (Element) nbestList.get(i);
        noUtt++;

        // In the xml tree: find utterance features for the 1-best predicted hypothesis
        java.util.List recList = nbestElem.getChildren("recognition");

        //				 Find the hypothesis that is classified by re-ranking procedure as minimal in rank:
        float bestRank = 100000;
        int bestRankIdx = -1;
        // Take from predictions file: the index of the 1-best
        for (int k = 1; k < recList.size(); k++) {
          String thisLine = br.readLine();
          if (thisLine == null)
            throw new Exception(
                "End of file in predictions file before reading the entire xml file!");
          float predictedRank = new Float(thisLine).floatValue();
          if (bestRank > predictedRank) {
            bestRankIdx = k;
            bestRank = predictedRank;
          }
        }
        // bestRankIdx = 1; // just for checking what's the SER for always choosing first hyp as the
        // best
        // System.out.println("best rank = " + bestRankIdx);
        if (recList.size() < bestRankIdx)
          System.out.println("Less than " + bestRankIdx + " recognitions !!! ");

        Element recElem = (Element) recList.get(bestRankIdx);

        Element semCorrectElem = recElem.getChild("semantically_correct");
        String semCorrect = semCorrectElem.getValue();
        if (semCorrect.equalsIgnoreCase("good")) serArray[i] = 0;
        else serArray[i] = 1;
      }

      String thisLine;
      if ((thisLine = br.readLine()) != null) {
        System.out.println(
            "There are still some " + "predictions while the xml file reached endOfFile!!! ");
        System.out.println(thisLine);
      }
      return serArray;
    } catch (IOException eIO) {
      eIO.printStackTrace();
    } catch (JDOMException eJDOM) {
      eJDOM.printStackTrace();
    } catch (NullPointerException nullE) {
      nullE.printStackTrace();
    }
    return null;
  }