Ejemplo n.º 1
0
  /** Encoding of a node so it can be reconstructed */
  public static String serialize(Node n, String base, PrefixMap prefixMap) {
    // See also Nodec.
    // See also OutputLangUtils - merge and this is a buffering call.

    if (n == null) return "<<null>>";

    if (n.isBlank()) {
      String str = n.getBlankNodeLabel();
      // c.f. OutputLangUtils
      if (onlySafeBNodeLabels) str = safeBNodeLabel(str);
      return "_:" + str;
    }

    if (n.isLiteral()) return FmtUtils.stringForLiteral((Node_Literal) n, null);

    if (n.isURI()) {
      String uri = n.getURI();
      return stringForURI(uri, base, prefixMap);
    }

    // Safe name?
    if (n.isVariable()) return "?" + n.getName();
    //
    //        if ( n.equals(Node.ANY) )
    //            return "ANY" ;

    throw new TDBException("Failed to turn a node into a string: " + n);
    // return null ;
  }
Ejemplo n.º 2
0
 private SWRLIndividualObject makeIndividalObject(final Node node) throws URISyntaxException {
   if (node.isVariable()) {
     final SWRLIndividualVariable var =
         swrlFactory.createIndividualVariable(new URI(varNS + node.getName()));
     vars.put(node.toString(), var);
     return var;
   }
   final OWLIndividual ind = owlModel.createIndividual(null, new URI(node.getURI()));
   return swrlFactory.wrapIndividual(ind);
 }
Ejemplo n.º 3
0
 private SWRLDataObject makeDataObject(final Node node) throws URISyntaxException {
   if (node.isVariable()) {
     final SWRLDataVariable var =
         swrlFactory.createDataVariable(new URI(varNS + node.getName()));
     vars.put(node.toString(), var);
     return var;
   }
   final OWLDataValue value =
       new OWLDataValueImpl(new LiteralImpl(node, (EnhGraph) owlModel.getImplementation()));
   return swrlFactory.wrapDataValue(value);
 }
Ejemplo n.º 4
0
  @Override
  public List<Context> apply(Context in) {
    Map<String, Node> oldBinds = in.getTyped(ContextKey.BINDINGS_KEY.toString());
    Map<String, Node> newBinds = new HashMap<String, Node>();
    newBinds.putAll(oldBinds);

    for (Node n : this.funcs.keySet()) {
      BaseValueFunction valFunc = this.funcs.get(n);
      List<Context> processedList = valFunc.apply(in);
      Context processed = processedList.get(0);
      Map<String, Node> processedBinds = processed.getTyped(ContextKey.BINDINGS_KEY.toString());
      newBinds.put(n.getName(), processedBinds.get(valFunc.getResultVarNode().getName()));
    }

    Context populatedIn = new Context();
    populatedIn.putAll(in);
    populatedIn.put(ContextKey.BINDINGS_KEY.toString(), newBinds);

    return applyRoot(populatedIn);
  }
Ejemplo n.º 5
0
 public void addIfVariable(Node possibleVariable, NodeMaker nodeMaker, AliasMap aliases) {
   if (!possibleVariable.isVariable()) return;
   add(possibleVariable.getName(), nodeMaker, aliases);
 }
Ejemplo n.º 6
0
 private static Node generateCountableNode(int count, Node node1, Node node2) {
   if (node2 == node1 && node2.isVariable()) {
     node2 = Var.alloc(node2.getName() + "_" + count);
   }
   return node2;
 }