Package com.hp.hpl.jena.graph

Examples of com.hp.hpl.jena.graph.Node$NodeMaker


        if ( false )
        {
            for ( ; qIter.hasNext() ; )
            {
                Binding b = qIter.nextBinding() ;
                Node n = b.get(var_x) ;
                System.out.println(FmtUtils.stringForNode(n)) ;
                System.out.println(b) ;
            }
            qIter.close() ;
        }
View Full Code Here


    {
        // No real need to check the pattern arguments because
        // the replacement triple pattern and regex will cope
        // but we illustrate testing here.

        Node nodeVar = argSubject.getArg() ;
        String pattern = NodeUtils.stringLiteral(argObject.getArg()) ;
        if ( pattern == null )
        {
            Log.warn(this, "Pattern must be a plain literal or xsd:string: "+argObject.getArg()) ;
            return new QueryIterNullIterator(execCxt) ;
View Full Code Here

        if ( ! nodeURI.isURI() )
            // Subject bound but not a URI
            return new QueryIterNullIterator(execCxt) ;

        // Subject is bound and a URI - get the localname as a Node
        Node localname = Node.createLiteral(nodeURI.getLocalName()) ;
       
        // Object - unbound variable or a value?
        if ( ! nodeLocalname.isVariable() )
        {
            // Object bound or a query constant.  Is it the same as the calculated value?
View Full Code Here

    }

    private void slot(Collection<Binding> bindings, Binding input, Node node, Var subjVar, Node nodeLocalname)
    {
        if ( ! node.isURI() ) return ;
        Node localname = Node.createLiteral(node.getLocalName()) ;
        if ( nodeLocalname.isVariable() )
        {
            // Object is an unbound variable.
            Binding b = new BindingMap(input) ;
            // Bind a pair for subject and object variables
View Full Code Here

   * @see com.hp.hpl.jena.reasoner.rulesys.Builtin#bodyCall(com.hp.hpl.jena.graph.Node[], int, com.hp.hpl.jena.reasoner.rulesys.RuleContext)
   */
  public boolean bodyCall(Node[] args, int length, RuleContext context) {
    BindingEnvironment env = context.getEnv();
    InfGraph graph = context.getGraph();
    Node s = env.getGroundVersion(args[0]);
    Node p = env.getGroundVersion(args[1]);
    Node o = env.getGroundVersion(args[2]);
    try {
      Triple t = Triple.create(s,p,o);
      Reifier r = graph.getReifier();
      Node a = Node.createAnon();
      r.reifyAs(a,t);
      env.bind(args[3],a);
      return true;
    } catch (Exception e) {
      return false;
View Full Code Here

  }
 
  public void headAction(Node[] args, int length, RuleContext context) {
    BindingEnvironment env = context.getEnv();
    InfGraph graph = context.getGraph();
    Node s = env.getGroundVersion(args[0]);
    Node p = env.getGroundVersion(args[1]);
    Node o = env.getGroundVersion(args[2]);
    try {
      Triple t = Triple.create(s,p,o);
      context.add(t);
      Node a = Node.createAnon();
      Reifier r = graph.getReifier();
      r.reifyAs(a,t);
      env.bind(args[3],a);
    } catch (Exception e) {
      e.printStackTrace(System.err);
View Full Code Here

  public boolean bodyCall(Node[] args, int length, RuleContext context) {
    BindingEnvironment env = context.getEnv();
    InfGraph graph = context.getGraph();

    Node s = env.getGroundVersion(args[0]);
    Node p = env.getGroundVersion(args[1]);
    ExtendedIterator i = graph.find(s,p,null);
    int n = i.toSet().size();
   
    TypeMapper tm = TypeMapper.getInstance();
    RDFDatatype type = tm.getTypeByName(XSD.xint.getURI());
    Node count = Node.createLiteral(Integer.toString(n),null,type);
    env.bind(args[2],count);
    return true;
  }
View Full Code Here

  /* (non-Javadoc)
   * @see com.hp.hpl.jena.reasoner.rulesys.Builtin#bodyCall(com.hp.hpl.jena.graph.Node[], int, com.hp.hpl.jena.reasoner.rulesys.RuleContext)
   */
  public boolean bodyCall(Node[] args, int length, RuleContext context) {
    BindingEnvironment env = context.getEnv();
    Node value = env.getGroundVersion(args[0]);
    TypeMapper tm = TypeMapper.getInstance();
    RDFDatatype type = tm.getTypeByName(PrintUtil.expandQname(args[2].toString()));
    Node cast = Node.createLiteral(value.getLiteral().getValue().toString(),null,type);
    env.bind(args[1],cast);
    return type.isValid(value.getLiteral().getValue().toString());
  }
View Full Code Here

  /* (non-Javadoc)
   * @see com.hp.hpl.jena.reasoner.rulesys.Builtin#bodyCall(com.hp.hpl.jena.graph.Node[], int, com.hp.hpl.jena.reasoner.rulesys.RuleContext)
   */
  public boolean bodyCall(Node[] args, int length, RuleContext context) {
    BindingEnvironment env = context.getEnv();
    Node namespace = env.getGroundVersion(args[0]);
    Node localName = env.getGroundVersion(args[1]);
    try {
      String ns = namespace.getLiteral().getValue().toString();
      String ln;
      try {
        ln = localName.getLiteral().getValue().toString();
      }
      // if the value is at odds with the datatype
      catch (Exception e) { ln = localName.getLiteral().toString(); }
      ln = URLEncoder.encode(ln,"UTF-8");
      URI uri = new URI(ns+(!ns.endsWith("#")&&!ns.endsWith("/")?"#":"")+ln);
      env.bind(args[2],Node.createURI(uri.toString()));
      return true;
    } catch (Exception e) {
View Full Code Here

      Object val = resultset.getObject(var);
      if (val == null)
        continue;

      // xsd:strings are just annoying...
      Node nodeVal;
      if (val instanceof String)
        nodeVal = Node.createLiteral((String) val);
      else
      {
        LiteralLabel ll = new LiteralLabel(val);
        nodeVal = Node.createLiteral(ll);
      }
     
      binding.put(var, nodeVal);
    }
   

    for (Node subject: pattern.getSubjects()) // bind subjects
    {
      if (subject.isConcrete()) continue; // nothing to do...
     
      Table table = pattern.getTableForSubject(subject);
     
      if (!table.hasPrimaryKeys()) // No row -> bnode mapping possible
      {
        binding.put(subject.getName(), Node.createAnon());
      }
      else
      {
        Map<String, Object> attvals = new HashMap<String, Object>();
       
        for (Col col: table.getPrimaryCols())
        {
          Object value = resultset.getObject(subject.getName() + "$" + col.getName() + "$prim");
          attvals.put(col.getName(), value);
        }
       
        Node node = table.keysToNode(attvals);
       
        binding.put(subject.getName(), node);
      }
    }
   
View Full Code Here

TOP

Related Classes of com.hp.hpl.jena.graph.Node$NodeMaker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.