property function extension sparql

Hmaida Abdelhedi

I want to write a property function extension sparql with arq jena, how can I write? Request:

SELECT *
WHERE {?Person f:Next(name) ?x.}

my function code:

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.jena.atlas.logging.Log;
import org.apache.jena.graph.Node;
import org.apache.jena.query.QueryBuildException;
import org.apache.jena.query.QueryException;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.RDFNode;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.Statement;
import org.apache.jena.rdf.model.StmtIterator;
import org.apache.jena.sparql.engine.ExecutionContext;
import org.apache.jena.sparql.engine.QueryIterator;
import org.apache.jena.sparql.engine.binding.Binding;
import org.apache.jena.sparql.engine.iterator.QueryIterNullIterator;
import org.apache.jena.sparql.pfunction.PFuncSimple;
import org.apache.jena.sparql.pfunction.PFuncSimpleAndList;
import org.apache.jena.sparql.pfunction.PropFuncArg;
import org.apache.jena.sparql.pfunction.PropertyFunction;
import org.apache.jena.sparql.pfunction.PropertyFunctionFactory;
import org.apache.jena.sparql.util.IterLib;



public class Next implements PropertyFunctionFactory {
@Override
public PropertyFunction create(final String uri)
{   
    return new PFuncSimple()
    {

        @Override
        public QueryIterator execEvaluated(final Binding parent, final Node        subject, final Node predicate, final Node object, final ExecutionContext execCxt) 
        {   
            Model model = ModelFactory.createDefaultModel();
InputStream is = null;
    try {
        is = new BufferedInputStream(
                new FileInputStream( "C:\\\\fichier rdf/journal.webscience.org-vivo.rdf"));
    } catch (FileNotFoundException ex) {
        Logger.getLogger(haschild.class.getName()).log(Level.SEVERE, null, ex);
    }
 model.read(new InputStreamReader(is), "");
 StmtIterator iter = model.listStatements();

extract the sebject , predicate and object from rdf:

 for (;iter.hasNext();) {
  Statement stmt      = iter.nextStatement();
Resource  sub   = stmt.getSubject();    
Property  pred = stmt.getPredicate();   
RDFNode   obj    = stmt.getObject();

comparison the suject and predicate of the rdf with subject and predicate of the request

 if ((sub.toString().equals(subject.toString()))||    (pred.toString().equals(predicate.toString())))
           return  new QueryIterPlainWrapper ((Iterator<Binding>) obj,execCxt);
            }
            return null;
        }
    };
}
    }

and how i can register my function

AndyS

Property functions look in syntax like regular properties. There isn't a special syntax.

?Person :somePropertyFunction ?x .

The property function has access to the subject and object of the triple pattern. There is also help for when subject or object are an RDF list.

Usually the arguments go as the object or object list and results are as a subject or subject list.

You shouldn't need to use .toString.

You can't cast obj to an Iterator<Binding>.

Take a look at some existing property functions. splitIRI is a simple one. concat might be useful to look at - it takes a list of argument (object position) and returns a subject (variable).

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

property function extension sparql

From Dev

Kotlin extension function on mutable property

From Dev

Sparql property filter

From Dev

Sparql property filter

From Dev

Sparql query with property paths

From Dev

How to make an extension function for getting variable or property name like ToString()

From Dev

How to get Dagger2 class property in extension function?

From Dev

How to get Dagger2 class property in extension function?

From Dev

Filter for property path in SPARQL 1.1

From Dev

Select property from an Individual SPARQL

From Dev

What is the lang function in SPARQL?

From Dev

year() function in SPARQL

From Dev

year() function in SPARQL

From Dev

SPARQL - query a property and return results for a related property

From Dev

A bug ? Property in an extension of UIView

From Dev

SPARQL - Order By "duplicates"/"rename" property, why?

From Dev

What does slash mean in a SPARQL property path?

From Dev

Sparql result not containing specified property included in results

From Dev

boundary for arbitrary property path in SPARQL 1.1

From Dev

SPARQL property path queries with arbitrary properties

From Dev

How to CONSTRUCT a property's transitive closure in SPARQL?

From Dev

Sparql query: find objects with same property objects

From Dev

sparql check for existing of a property and give zero to the answer

From Dev

SPARQL 1.1 Property Paths in Marklogic 8

From Dev

How to get individuals data property value in sparql

From Dev

Sparql query for additional data property assertion

From Dev

sparql check for existing of a property and give zero to the answer

From Dev

SPARQL: Figure out high data property values

From Dev

Prototype, array extension, and object property

Related Related

HotTag

Archive