/**
   * 获得同义词,即由词获得以此词为概念词的异名,或以此词为异名的概念词
   *
   * @param word
   * @return 同义词XML字符串 例如:搜索"大黄"的同义词,返回XML: <thesauruses> <concept>水黄</concept>
   *     <concept>小大黄</concept> <concept>山大黄</concept> <alias>Dheum Officinale</alias>
   *     <alias>肤如</alias> <alias>黄良</alias> <alias>da huang</alias> <alias>牛舌大黄</alias>
   *     <alias>川军</alias> <alias>蜀大黄</alias> <alias>锦纹</alias> <alias>生军</alias> <alias>火参</alias>
   *     <alias>将军</alias> <alias>锦纹大黄</alias> <alias>RHEUM OFFICINALE</alias> <alias>Rheum palmatum
   *     L.;Rheum tanguticum Maxim.ex Balf.;Rheum officinale Baill.</alias> <alias>Radix et Rhizoma
   *     Rhei(拉);rhubarb root and rhizome</alias> </thesauruses>
   */
  private static String getThesaurus(String word) {
    Document doc = DocumentHelper.createDocument();
    Element e = doc.addElement("thesauruses");

    List<String> thesauruses = ConceptEngine.getConceptByAlias(word);
    for (int i = 0; i < thesauruses.size(); i++)
      e.addElement("concept").setText(thesauruses.get(i));

    thesauruses = ConceptEngine.getAliasByConcept(word);
    for (int i = 0; i < thesauruses.size(); i++) e.addElement("alias").setText(thesauruses.get(i));

    return e.asXML();
  }
Esempio n. 2
0
 private void buildRelaMap(Element centerNode) {
   String concept = centerNode.elementText("Label");
   Element relaXML = ConceptEngine.getContent(concept, "关联词");
   // <result db="中医药学语言系统" rela="被…使用">论利湿清热</result>
   String objectUri = ConceptEngine.skosPrefix + "#Concept";
   List relas = relaXML.elements();
   for (int i = 0; i < relas.size() && i < count; i++) {
     Element rela = (Element) relas.get(i);
     String content = rela.getText();
     Element node = null;
     Boolean isNewNode = true;
     if (nodes.containsKey(content)) {
       Element e = (Element) nodes.get(content);
       if (e.elementText("TypeUri").equals(objectUri)) {
         isNewNode = false;
         node = e;
       }
     }
     if (isNewNode) {
       node = nodeArray.addElement("Node").addAttribute("id", nodeID++ + "");
       node.addElement("Label").addText(content);
       node.addElement("TypeUri").addText(objectUri);
       node.addElement("Type").addText("事物");
       nodes.put(content, node);
     }
     Element edge = edgeArray.addElement("Edge").addAttribute("id", edgeID++ + "");
     edge.addElement("Label").addText(rela.attributeValue("rela"));
     edge.addElement("TypeUri").addText("rela");
     edge.addElement("FromID").addText(centerNode.attributeValue("id"));
     edge.addElement("ToID").addText(node.attributeValue("id"));
   }
 }
Esempio n. 3
0
 private void addRelations(
     Element centerNode, String concept, List<?> relations, Boolean isOpposed) {
   if (!isOpposed)
     System.out.println("++++++++++++++" + concept + "++++++++++++++++++" + centerNode.asXML());
   for (int i = 0; i < relations.size(); i++) {
     Element relation = (Element) relations.get(i);
     String propertyUri = relation.attributeValue("propertyUri");
     if (propertyUri.equals(ConceptEngine.ontoPrefix + "#hasRela")) {
       buildRelaMap(centerNode);
       continue;
     }
     if (propertyUri.equals(ConceptEngine.ontoPrefix + "#relaConcept")) continue;
     String propertyLabel = relation.attributeValue("property");
     String objectUri = relation.attributeValue("objectUri");
     String objectLabel = relation.attributeValue("object");
     String sparql = ConceptEngine.getContentSparql(concept, propertyUri, false, isOpposed);
     QueryResult r;
     try {
       r = QueryEngine.sparql(sparql);
       if (r == null) continue;
       int ct = 0;
       while (r.next() && ct < count) {
         ct++;
         String content = r.getString(0);
         Element node = null;
         Boolean isNewNode = true;
         if (nodes.containsKey(content)) {
           Element e = (Element) nodes.get(content);
           if (e.elementText("TypeUri").equals(objectUri)) {
             isNewNode = false;
             node = e;
           }
         }
         if (isNewNode) {
           node = nodeArray.addElement("Node").addAttribute("id", nodeID++ + "");
           node.addElement("Label").addText(content);
           node.addElement("TypeUri").addText(objectUri);
           node.addElement("Type").addText(objectLabel);
           nodes.put(content, node);
         }
         Element edge = edgeArray.addElement("Edge").addAttribute("id", edgeID++ + "");
         edge.addElement("Label").addText(propertyLabel);
         edge.addElement("TypeUri").addText(propertyUri);
         edge.addElement("FromID")
             .addText(isOpposed ? node.attributeValue("id") : centerNode.attributeValue("id"));
         edge.addElement("ToID")
             .addText(isOpposed ? centerNode.attributeValue("id") : node.attributeValue("id"));
       }
     } catch (java.lang.NullPointerException e) {
       logger.error("Dart Grid: Query Error! --> " + concept + "(" + propertyLabel + ")");
       r = null;
       e.printStackTrace();
     }
   }
   // if(isOpposed)
   //	System.out.println("++++++++++++++++++++++++++++++++");
 }