@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); } } }
/** * Extract triplesMap contents. * * @param triplesMap * @param r2rmlMappingGraph * @param triplesMapSubject * @param triplesMapResources * @param storedTriplesMaps * @throws InvalidR2RMLStructureException * @throws InvalidR2RMLSyntaxException * @throws R2RMLDataError */ private static void extractTriplesMap( SesameDataSet r2rmlMappingGraph, Resource triplesMapSubject, Map<Resource, TriplesMap> triplesMapResources) throws InvalidR2RMLStructureException, InvalidR2RMLSyntaxException, R2RMLDataError { if (log.isDebugEnabled()) { log.debug( "[RMLMappingFactory:extractTriplesMap] Extract TriplesMap subject : " + triplesMapSubject.stringValue()); } TriplesMap result = triplesMapResources.get(triplesMapSubject); // Extract TriplesMap properties // MVS: create LogicalSource LogicalSource logicalSource = extractLogicalSource(r2rmlMappingGraph, triplesMapSubject); // Extract subject // Create a graph maps storage to save all met graph uri during parsing. Set<GraphMap> graphMaps = new HashSet<GraphMap>(); // log.debug("[RMLMappingFactory:extractTriplesMap] Current number of created graphMaps : " // + graphMaps.size()); SubjectMap subjectMap = extractSubjectMap(r2rmlMappingGraph, triplesMapSubject, graphMaps, result); // log.debug("[RMLMappingFactory:extractTriplesMap] Current number of created graphMaps : " // + graphMaps.size()); // Extract predicate-object maps Set<PredicateObjectMap> predicateObjectMaps = extractPredicateObjectMaps( r2rmlMappingGraph, triplesMapSubject, graphMaps, result, triplesMapResources); log.debug( "[RMLMappingFactory:extractTriplesMap] Current number of created graphMaps : " + graphMaps.size()); // Fill triplesMap for (PredicateObjectMap predicateObjectMap : predicateObjectMaps) { result.addPredicateObjectMap(predicateObjectMap); } result.setLogicalSource(logicalSource); result.setSubjectMap(subjectMap); log.debug( "[RMLMappingFactory:extractTriplesMap] Extract of TriplesMap subject : " + triplesMapSubject.stringValue() + " done."); }
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(); }
@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); } }