Sparql query with customized filter

2 views
Skip to first unread message

Cong Wang

unread,
Feb 11, 2015, 12:12:44 PM2/11/15
to sta...@clarkparsia.com
Hi,

I implemented a edit distance filter using jena-arq, and tried to sparql query based on it. But it returns error (works on jena), 

"
        Exception in thread "main" com.hp.hpl.jena.sparql.ARQException: com.complexible.stardog.StardogException: com.complexible.stardog.plan.eval.ExecutionException: There was an error while creating a new query plan

"

Is that stardog doesn't support customized filter? 

Here isthe code:

"

public class LevenshteinFilter extends FunctionBase2 {
public NodeValue exec(NodeValue value1, NodeValue value2) {
int i = StringUtils.getLevenshteinDistance(value1.asString(),
value2.asString());
return NodeValue.makeInteger(i);
}
}

...


Connection aConn = ConnectionConfiguration.to("myDB").server("snarl://localhost:5820/").credentials("admin", "admin").connect();
Model aModel = SDJenaFactory.createModel(aConn);
FunctionRegistry.get().put(functionUri, LevenshteinFilter.class);

String sparql = "PREFIX rdfs:<http://www.w3.org/2000/01/rdf-schema#>"
+ "SELECT ?s1 ?s2 ?o1 ?o2 WHERE { ?s1 rdfs:label ?o1. ?s2 rdfs:label ?o2 ."
+ " FILTER(STRSTARTS(str(?s1), \"http://www.wikidata\") && STRSTARTS(str(?s2), \"http://wordnet-rdf\") && <"
+ functionUri + ">(str(?o1),str(?o2)<3))}  LIMIT 10";

QueryExecution qexec = QueryExecutionFactory.create(sparql, aModel);
ResultSet rs = qexec.execSelect();
while (rs.hasNext()) {
System.out.println(rs.next());
}
"

Thanks.

Kendall Clark

unread,
Feb 11, 2015, 12:23:47 PM2/11/15
to stardog
Hi,

Did you follow the extensibility patterns described at https://github.com/clarkparsia/stardog-examples/tree/master/examples/function ?

Cheers,
Kendall

--
-- --
You received this message because you are subscribed to the C&P "Stardog" group.
To post to this group, send email to sta...@clarkparsia.com
To unsubscribe from this group, send email to
stardog+u...@clarkparsia.com
For more options, visit this group at
http://groups.google.com/a/clarkparsia.com/group/stardog?hl=en

Cong Wang

unread,
Feb 11, 2015, 12:44:32 PM2/11/15
to sta...@clarkparsia.com
Hi Kendall,

Thanks for the information. I didn't find this useful description. 

However, I can't find the jar package containing "com.complexible.stardog.plan.filter.functions.AbstractFunction;" I had added all jars into my library.

To unsubscribe from this group and stop receiving emails from it, send an email to stardog+u...@clarkparsia.com.



--
Cong Wang
Ph.D Candidate,
Kno.e.sis Center,
Wright State University.

Cong Wang

unread,
Feb 11, 2015, 12:55:54 PM2/11/15
to sta...@clarkparsia.com
I guess that's the new feature in the unreleased stardog 3.0?  am I right?

Kendall Clark

unread,
Feb 11, 2015, 1:00:46 PM2/11/15
to stardog
Custom aggregates are new for 3.0. Custom functions have been around for a while.

To reproduce yr bug report, we need the code yr using and the version of Stardog if it's not 2.2.4. You can send it to the list here or email me directly.

Cheers,
Kendall

On Wed, Feb 11, 2015 at 12:55 PM, Cong Wang <joshu...@gmail.com> wrote:
I guess that's the new feature in the unreleased stardog 3.0?  am I right?
On Wed, Feb 11, 2015 at 12:44 PM, Cong Wang <joshu...@gmail.com> wrote:
Hi Kendall,

Thanks for the information. I didn't find this useful description. 

However, I can't find the jar package containing "com.complexible.stardog.plan.filter.functions.AbstractFunction;" I had added all jars into my library.
On Wed, Feb 11, 2015 at 12:23 PM, Kendall Clark <ken...@clarkparsia.com> wrote:
Hi,

Did you follow the extensibility patterns described at https://github.com/clarkparsia/stardog-examples/tree/master/examples/function ?

Cheers,
Kendall

Cong Wang

unread,
Feb 11, 2015, 1:05:44 PM2/11/15
to sta...@clarkparsia.com
Thanks. 

I am using the Stardog 2.2.4. 

And when I declare a Class "public class LevenshteinFilter extends AbstractFunction implements StringFunction" I cannot find the corresponding imports.

I don't have further code due to the missing imports.

Best.

Mike Grove

unread,
Feb 11, 2015, 1:20:51 PM2/11/15
to stardog
On Wed, Feb 11, 2015 at 1:05 PM, Cong Wang <joshu...@gmail.com> wrote:
Thanks. 

I am using the Stardog 2.2.4. 

And when I declare a Class "public class LevenshteinFilter extends AbstractFunction implements StringFunction" I cannot find the corresponding imports.

I don't have further code due to the missing imports.

Cong Wang

unread,
Feb 11, 2015, 1:26:19 PM2/11/15
to sta...@clarkparsia.com
Hi Mike,

Yes, I found this example. But there seems no corresponding .jar package in Stardog 2.2.4.

Mike Grove

unread,
Feb 11, 2015, 1:31:13 PM2/11/15
to stardog
On Wed, Feb 11, 2015 at 1:26 PM, Cong Wang <joshu...@gmail.com> wrote:
Hi Mike,

Yes, I found this example. But there seems no corresponding .jar package in Stardog 2.2.4.

It sounds like your classpath is wrong.  You should review which jars you've added, that class is in the stardog-2.2.4.jar.

Cheers,

Mike

Cong Wang

unread,
Feb 11, 2015, 1:57:24 PM2/11/15
to sta...@clarkparsia.com
Oh, Thanks. I found it.

It's in server/dbms/ folder. I just added all jars in client..

Thanks a lot.

Cong Wang

unread,
Feb 11, 2015, 2:52:55 PM2/11/15
to sta...@clarkparsia.com
A little bit complex, but I finally made my filter work.

Thanks all.
Reply all
Reply to author
Forward
0 new messages