openRDF.org Welcome Guest   | Login   
  Search  
  Index  | Recent Threads  | Who's Online  | User List  | Search  | Help  | RSS feeds

Forum closing down
This forum will be closing down due to extensive spamming activities. As a first step, registration of new members has been disabled. Existing members will be able to use the forum for now, but please consider using the sesame-general mailing list instead.


Quick Go »
Thread Status: Normal
Total posts in this thread: 5
[Add To My Favorites] [Watch this Thread] [Post new Thread]
Author
Previous Thread This topic has been viewed 1838 times and has 4 replies Next Thread
Aug 31, 2008 10:38:19 AM

turnguard
Regular
Member's Avatar


Joined: Mar 22, 2008
Posts: 34
Status: Offline
SPARQL - Filter Namespaces Reply to this Post
Reply with Quote

hy there!

1. is there a native sparql [ maybe serql ] way of filtering query out according to a namespace :
for example if you have owl and skos is your store and want to only show classes with the
skos-namespace [ i can't use contexts to make them look different ] .

2. if not : is there a way i could teach the sparql - engine the arq-extension functions from here
http://jena.sourceforge.net/ARQ/library-function.html

any help appreciated
wkr www.turnguard.com
Show Printable Version of Post        Hidden to Guest    http://www.2sea.org    tschyrgie [Link] Report threatening or abusive post: please login first  Go to top 
Aug 31, 2008 7:37:15 PM

turnguard
Regular
Member's Avatar


Joined: Mar 22, 2008
Posts: 34
Status: Offline
Re: SPARQL - Filter Namespaces Reply to this Post
Reply with Quote

i allready found out myself , very simple ...

public class NameSpace implements Function {

public String getURI() {
return "http://www.turnguard.com/functions#namespace";
}

public Value evaluate(ValueFactory valueFactory, Value... args) throws ValueExprEvaluationException {
try {
URI u = (URI)args[0];
return valueFactory.createURI(u.getNamespace());
} catch (Exception e){
throw new ValueExprEvaluationException();
}
}
}

might not be elegant, but it exactly does what i need
Show Printable Version of Post        Hidden to Guest    http://www.2sea.org    tschyrgie [Link] Report threatening or abusive post: please login first  Go to top 
Aug 31, 2008 7:44:31 PM

turnguard
Regular
Member's Avatar


Joined: Mar 22, 2008
Posts: 34
Status: Offline
Re: SPARQL - Filter Namespaces Reply to this Post
Reply with Quote

so i can use the above class like this

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX skos: <http://www.w3.org/2004/02/skos/core#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX owl: <http://www.w3.org/2002/07/owl#>
PREFIX tg:<http://www.turnguard.com/functions#>

SELECT DISTINCT ?Class
WHERE {
{
?Class rdf:type <http://www.w3.org/2000/01/rdf-schema#Class> .
OPTIONAL {
?Class rdfs:subClassOf <http://www.w3.org/2000/01/rdf-schema#Class> .
}
} . FILTER(tg:namespace(?Class)=<http://www.w3.org/2004/02/skos/core#>)
}
Show Printable Version of Post        Hidden to Guest    http://www.2sea.org    tschyrgie [Link] Report threatening or abusive post: please login first  Go to top 
Sep 1, 2008 8:22:00 AM

arjohn
OpenRDF project lead
Member's Avatar

The Netherlands
Joined: Jan 23, 2004
Posts: 1289
Status: Offline
Re: SPARQL - Filter Namespaces Reply to this Post
Reply with Quote

Good that you've found this yourself. Info for any future readers: one can implement the org.openrdf.query.algebra.evaluation.function.Function interface to implement your own functions. After registering the function implementation in the appropriate service description file (/META-INF/services/org.openrdf.query.algebra.evaluation.function.Function) it will be available to Sesame's query engine.

Note that SeRQL natively supports the NAMESPACE function, e.g.:
SELECT DISTINCT Class
FROM {Class} rdf:type {rdfs:Class};
[rdfs:subClassOf {rdfs:Class}]
WHERE
NAMESPACE(Class) = skos:
}
USING NAMESPACE
skos = <http://www.w3.org/2004/02/skos/core#>

----------------------------------------
Arjohn Kampman, OpenRDF project lead, Aduna
Show Printable Version of Post        Hidden to Guest [Link] Report threatening or abusive post: please login first  Go to top 
Sep 1, 2008 8:47:34 AM

turnguard
Regular
Member's Avatar


Joined: Mar 22, 2008
Posts: 34
Status: Offline
Re: SPARQL - Filter Namespaces Reply to this Post
Reply with Quote

or register the new function like so

org.openrdf.query.algebra.evaluation.function.FunctionRegistry.getInstance().add(new Namespace());


if you're experiencing any troubles with META-INF and tomcat or so..

Namespace implements Function in this case . see above

wkr turnguard
Show Printable Version of Post        Hidden to Guest    http://www.2sea.org    tschyrgie [Link] Report threatening or abusive post: please login first  Go to top 
[Show Printable Version of Thread] [Post new Thread]