Exemplo n.º 1
0
  public static void MDVgenerate(String modelPath)
      throws ParserConfigurationException, SAXException, IOException, TException,
          UnknownWordException {

    com.medallia.word2vec.Word2VecModel model = Word2Vec_Medallia.loadModel(modelPath);

    LandxmlLexicon lexicon = readLandXML();
    HashMap<Integer, LandxmlNode> landXMLEnt = lexicon.getMap();

    try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
      while (true) {
        System.out.print("Enter word or term (press ENTER to break): ");
        String phrase = br.readLine().trim();
        if (phrase.equals("")) {
          System.out.println("Programe is shut off.");
          break;
        }

        // interpreting input string
        List<Concept> cons = Concept.getConcepts(phrase);
        TreeMap<String, Double> matchEntries = new TreeMap<String, Double>();
        for (Concept con : cons) {
          matchEntries.putAll(lexicon.searchAlgorithm2(model, con, 30, 10, 0.3));
        }

        // print the results
        System.out.println("********Mapping result**********************************");
        System.out.println("--------Required data---------------------LandXML entity");

        matchEntries = (TreeMap<String, Double>) shortTreeMap.sortByValues(matchEntries);
        int i = 0;
        for (Entry e : matchEntries.entrySet()) {
          i++;
          if (i > 5) break;
          String sourceEnt = e.getKey() + ":" + e.getValue();
          System.out.println(sourceEnt);
        }
        System.out.println("********************************************************");
      }
    }
  }
Exemplo n.º 2
0
  public static LandxmlLexicon readLandXML()
      throws ParserConfigurationException, SAXException, IOException {

    LandxmlLexicon landxmlLexicon = new LandxmlLexicon("LandxmlSchema");

    HashMap<Integer, LandxmlNode> landxmlNodeList = new HashMap<Integer, LandxmlNode>();

    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    DocumentBuilder db = dbf.newDocumentBuilder();
    File file = new File(landxmlSchemaPath);
    if (file.exists()) {
      org.w3c.dom.Document doc = db.parse(file);
      Element docEle = doc.getDocumentElement();

      HashSet<Node> nodeList = NodeList2List(docEle.getElementsByTagName("xs:element"));
      nodeList.addAll(NodeList2List(docEle.getElementsByTagName("xs:simpleType")));
      landxmlLexicon.addNodes(nodeList);
    }

    landxmlLexicon.print(landxmlDir);
    return landxmlLexicon;
  }