Example #1
0
  public static int calcWidth(PrefixMap prefixMap, String baseURI, Node p) {
    if (!prefixMap.contains(rdfNS) && RDF_type.equals(p)) return 1;

    String x = prefixMap.abbreviate(p.getURI());
    if (x == null) return p.getURI().length() + 2;
    return x.length();
  }
 private RDFNode checkUri(Node node, Model map) {
   if (node.isURI()) {
     String uri = node.getURI();
     if (uri.contains("{")) {
       List<String> colList = FormatUtil.extractCols(uri);
       uri = uri.replaceAll("\\{.*?}", "\\{\\}");
       Set<String> existing = joinData.get(uri);
       if (existing == null) {
         existing = new HashSet<String>();
       }
       existing.addAll(colList);
       joinData.put(uri, existing);
     }
   }
   return map.asRDFNode(node);
 }
Example #3
0
  @Override
  public void emitTriples(
      RdfEmitterContext emitterContext,
      Object entity,
      Node subject,
      Graph shapeGraph,
      Consumer<Triple> sink) {

    @SuppressWarnings("unchecked")
    Map<? super Object, ? super Object> map = createMapView.apply(entity);

    int i = 1;
    for (Entry<?, ?> e : map.entrySet()) {
      Object k = e.getKey();
      Object v = e.getValue();

      Node eNode = NodeFactory.createURI(subject.getURI() + "-" + i);

      // persistenceContext.
      // persistenceContext.entityFor(new TypedNode(rdfType, node));

      //            Node kNode = null; // emitterContext.getValueNode(entity,
      // propertyName)//RdfPersistenceContextImpl.getOrCreateRootNode(persistenceContext,
      // typeFactory, k);
      //            Node vNode = null;
      // //RdfPersistenceContextImpl.getOrCreateRootNode(persistenceContext, typeFactory, v);

      //            emitterContext.add(k, entity, "key" + i);
      //            emitterContext.add(v, entity, "value" + i);

      // Node keyNode = emitterContext.

      // Node kNode = emitterContext.getValueNode(entity, "key" + i, v);
      // Node vNode = emitterContext.getValueNode(entity, "value" + i, v);

      Node kNode = emitterContext.requestResolution(k);
      Node vNode = emitterContext.requestResolution(v);

      sink.accept(new Triple(subject, entry.asNode(), eNode));
      sink.accept(new Triple(eNode, key.asNode(), kNode));
      sink.accept(new Triple(eNode, value.asNode(), vNode));

      ++i;
    }
  }
Example #4
0
  private QueryIterator concreteSubject(
      Binding binding, Node s, Node score, Node literal, StrMatch match, ExecutionContext execCxt) {
    if (!s.isURI()) {
      log.warn("Subject not a URI: " + s);
      return IterLib.noResults(execCxt);
    }

    String qs = match.getQueryString();
    ListMultimap<String, TextHit> x =
        query(match.getProperty(), match.getQueryString(), -1, execCxt);

    if (x == null) // null return value - empty result
    return IterLib.noResults(execCxt);

    List<TextHit> r = x.get(s.getURI());

    return resultsToQueryIterator(binding, s, score, literal, r, execCxt);
  }
  /**
   * Instantiates a new sparql construct function.
   *
   * @param conf the graph with dataflow definition
   * @param confRoot the specific node in the graph representing the producer configuration
   * @param map the map to access the other defined producers
   * @see RDFProducer
   */
  public SparqlConstructFunction(Graph conf, Node confRoot, final ProducerMap map) {
    URI baseURI = URI.create(confRoot.getURI());

    Node inputNode = GraphUtils.getSingleValueOptProperty(conf, confRoot, DF.input.asNode());
    inputProducer =
        (inputNode != null) ? map.getProducer(inputNode) : EmptyGraphProducer.getInstance();

    Node queryAsInputNode = NodeFactory.createURI(baseURI.resolve("#query").toString());

    Node queryNode = GraphUtils.getSingleValueOptProperty(conf, confRoot, DF.configTxt.asNode());
    String queryTxt = (queryNode != null) ? queryNode.getLiteralLexicalForm() : null;

    Node configNode = GraphUtils.getSingleValueOptProperty(conf, confRoot, DF.config.asNode());
    RDFProducer configProducer = (configNode != null) ? map.getProducer(configNode) : null;

    Node configRootNode =
        GraphUtils.getSingleValueOptProperty(conf, confRoot, DF.configRoot.asNode());
    if (configRootNode == null) configRootNode = configNode;
    if (configRootNode == null && inputNode != null) {
      Iterator<Node> namedInputNodes =
          GraphUtils.getPropertyValues(conf, inputNode, DF.namedInput.asNode());
      while (namedInputNodes.hasNext()) {
        Node namedInputNode = namedInputNodes.next();
        if (conf.contains(namedInputNode, DF.id.asNode(), queryAsInputNode)) {
          configRootNode =
              GraphUtils.getSingleValueProperty(conf, namedInputNode, DF.input.asNode());
          break;
        }
      }
    }

    //		String configRootURI = (configRootNode != null && configRootNode.isURI()) ?
    // configRootNode.getURI() : null;

    queryProducer =
        new CoalesceQueryProducer(
            new GraphQueryProducer(
                new CoalesceGraphProducer(
                    configProducer, new SelectGraphProducer(inputProducer, queryAsInputNode)),
                configRootNode /*NodeFactory.createURI(baseURI.resolve("").toString())*/),
            new StringQueryProducer(queryTxt, baseURI.toString()));
    //		final Model confModel = ModelFactory.createModelForGraph(conf);
    //		Resource constructResource =
    //			confModel
    //					.getRDFNode(confRoot)
    //					.asResource()
    //					.getPropertyResourceValue(SPINX.config);
    //		Iterator<Producer> fromGraphProds =
    //			confModel
    //					.getRDFNode(confRoot)
    //					.asResource()
    //					.listProperties(SPINX.from)
    //					.mapWith(new Map1<Statement, Producer>() {
    //						@Override
    //						public Producer map1(Statement stmt) {
    //							return map.getProducer(stmt.getObject().asNode());
    //						}
    //					});
    // defaultProd = null;
    //		if (!fromGraphProds.hasNext()) {
    //			defaultProd = EmptyGraphProducer.getInstance();
    //		} else {
    //			defaultProd = fromGraphProds.next();
    //			if (fromGraphProds.hasNext()) {
    //				defaultProd =
    //					new UnionFunction(
    //							new ConcatenatedIterator<Producer>(
    //									new SingletonIterator<Producer>(defaultProd),
    //									fromGraphProds));
    //			}
    //		}
    //		Iterator<Node> fromNamedGraphNames =
    //			confModel
    //					.getRDFNode(confRoot)
    //					.asResource()
    //					.listProperties(SPINX.fromNamed)
    //					.mapWith(new Map1<Statement, Node>() {
    //						@Override
    //						public Node map1(Statement stmt) {
    //							return stmt.getObject().asNode();
    //						}
    //					});
    //		while (fromNamedGraphNames.hasNext()) {
    //			Node graphNames = fromNamedGraphNames.next();
    //			prodMap.put(graphNames, map.getProducer(graphNames));
    //		}

    //		query = QueryFactory.toQuery(conf, constructResource.asNode());
    //		if (query == null)
    //			throw new RuntimeException("Parsing Error");

    /*
    // debug
    Graph revEnginedGraph = SpinxFactory.fromQuery(query);
    System.out.println();
    System.out.println("**********************************");
    System.out.println("*** Reverse Engine query graph ***");
    System.out.println("**********************************");
    ModelFactory.createModelForGraph(revEnginedGraph).write(System.out,"N3");
    System.out.println("**********************************");
    System.out.println();
    */

    /*
    SPINFactory.asExpression(constructResource);
    query = ARQFactory.get().createQuery(SPINFactory.asQuery(constructResource));
    */
    /*
    Iterator<String> graphUris =
    	new ConcatenatedIterator<String>(
    			query.getGraphURIs().iterator(),
    			query.getNamedGraphURIs().iterator());
    while (graphUris.hasNext()) {
    	Node node = confModel.getResource(graphUris.next()).asNode();
    	prodMap.put(node, (GraphProducer) map.getProducer(node));
    }
    */
  }