예제 #1
0
  @Override
  public void execute_node(
      SesameDataSet dataset,
      String expression,
      TriplesMap parentTriplesMap,
      RMLPerformer performer,
      Object node,
      Resource subject) {
    // still need to make it work with more nore-results
    // currently it handles only one

    if (expression.startsWith("/")) expression = expression.substring(1);

    Node node2 = (Node) node;
    Nodes nodes = node2.query(expression, nsContext);

    for (int i = 0; i < nodes.size(); i++) {
      Node n = nodes.get(i);
      if (subject == null) performer.perform(n, dataset, parentTriplesMap);
      else {
        RMLProcessorFactory factory = new ConcreteRMLProcessorFactory();
        RMLProcessor subprocessor =
            factory.create(map.getLogicalSource().getReferenceFormulation());
        RMLPerformer subperformer = new NodeRMLPerformer(subprocessor);
        subperformer.perform(n, dataset, parentTriplesMap, subject);
      }
    }
  }
예제 #2
0
  public String execute(Node node, String expression) throws SaxonApiException {

    Processor proc = new Processor(false);
    XPathCompiler xpath = proc.newXPathCompiler();
    DocumentBuilder builder = proc.newDocumentBuilder();

    String source = getClass().getResource(map.getLogicalSource().getIdentifier()).getFile();

    XdmNode doc = builder.build(new File(source));
    String expre = replace(node, expression);
    expression =
        expression.replaceAll(
            "\\{" + expression.split("\\{")[1].split("\\}")[0] + "\\}", "'" + expre + "'");

    XPathSelector selector = xpath.compile(expression).load();
    selector.setContextItem(doc);

    // Evaluate the expression.
    Object result = selector.evaluate();

    return result.toString();
  }
예제 #3
0
  @Override
  public void execute(
      final SesameDataSet dataset,
      final TriplesMap map,
      final RMLPerformer performer,
      InputStream input) {
    try {
      this.map = map;
      String reference = getReference(map.getLogicalSource());
      // Inititalize the XMLDog for processing XPath
      // an implementation of javax.xml.namespace.NamespaceContext
      // DefaultNamespaceContext dnc = new DefaultNamespaceContext();
      DefaultNamespaceContext dnc = get_namespaces();
      XMLDog dog = new XMLDog(dnc);

      // adding expression to the xpathprocessor
      dog.addXPath(reference);

      jlibs.xml.sax.dog.sniff.Event event = dog.createEvent();

      // event.setXMLBuilder(new DOMBuilder());
      // use XOM now
      event.setXMLBuilder(new XOMBuilder());

      event.setListener(
          new InstantEvaluationListener() {
            // When an XPath expression matches
            @Override
            public void onNodeHit(Expression expression, NodeItem nodeItem) {
              Node node = (Node) nodeItem.xml;
              // if(!nodeItem.namespaceURI.isEmpty())
              // log.info("namespace? " + nodeItem.namespaceURI);
              // else
              // log.info("no namespace.");
              // Let the performer do its thing
              performer.perform(node, dataset, map);
              // System.out.println("XPath: " + expression.getXPath() + " has hit: " +
              // node.getTextContent());
            }

            @Override
            public void finishedNodeSet(Expression expression) {
              // System.out.println("Finished Nodeset: " + expression.getXPath());
            }

            @Override
            public void onResult(Expression expression, Object result) {
              // this method is called only for xpaths which returns primitive result
              // i.e result will be one of String, Boolean, Double
              // System.out.println("XPath: " + expression.getXPath() + " result: " + result);
            }
          });
      // Execute the streaming

      // dog.sniff(event, new InputSource(new FileInputStream(fileName)));
      dog.sniff(event, new InputSource(input));
    } catch (SAXPathException ex) {
      Logger.getLogger(XPathProcessor.class.getName()).log(Level.SEVERE, null, ex);
    } catch (XPathException ex) {
      Logger.getLogger(XPathProcessor.class.getName()).log(Level.SEVERE, null, ex);
    }
  }