Exemplo n.º 1
0
  private XFacetedQuery XML2Query(Document doc) {
    try {
      Node node = null;
      NamedNodeMap map = null;

      node = doc.getElementsByTagName("action").item(0);
      map = node.getAttributes();

      // create XFacetedQuery
      node = doc.getElementsByTagName("targetNode").item(0);
      map = node.getAttributes();
      int target = new Integer(map.getNamedItem("index").getNodeValue()).intValue();

      CatRelGraph graph = schemaFactory.createCatRelGraph();
      node = doc.getElementsByTagName("queryNode").item(0);
      graph.add(createGeneralCategory(node));
      // System.out.println("name="+node.getNodeName());
      addRelations(graph, 0, node.getChildNodes());
      System.out.println(graph);
      System.out.println("target=" + target);

      XFacetedQuery query = searchFactory.createXFacetedQuery();
      query.setSearchTarget(target);
      query.setQueryConstraint(graph);
      query.setResultSpec(searchFactory.createXFacetedResultSpec());
      return query;
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return null;
  }
Exemplo n.º 2
0
 private void addRelations(CatRelGraph graph, int fromNodeIndex, NodeList nodes)
     throws NoSuchAlgorithmException, DOMException {
   if (nodes == null) return;
   for (int i = 0; i < nodes.getLength(); i++) {
     Node node = nodes.item(i);
     if (node.getNodeName().equals("#text")) continue;
     // System.out.println("name="+node.getNodeName());
     graph.add(createGeneralCategory(node));
     int toNodeIndex = graph.numOfNodes() - 1;
     NamedNodeMap map = node.getAttributes();
     if (map.getNamedItem("inverse").getNodeValue().equals("0")) {
       graph.add(
           schemaFactory.createRelation(map.getNamedItem("relation").getNodeValue()),
           fromNodeIndex,
           toNodeIndex);
     } else {
       graph.add(
           schemaFactory.createRelation(map.getNamedItem("relation").getNodeValue()),
           toNodeIndex,
           fromNodeIndex);
     }
     addRelations(graph, toNodeIndex, node.getChildNodes());
   }
 }