SPARQL-DL query with owl-api - sparql

I'm writing an application using OWL-API and Hermit Reasoner. I would like to query data using SPARQL-DL by submitting query like:
PREFIX wine: <http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#>
SELECT ?i
WHERE { Type(?i, wine:PinotBlanc) }
OR WHERE { Type(?i, wine:DryRedWine) }
Can I Do this directy with owl-api or should I use an external library (http://www.derivo.de/en/resources/sparql-dl-api/ ) ? ( I need something like
queryEngine.query(my_query); )

As in July 2013, the OWL-API does not support natively SPARQL-DL. You need to plug a third party library in order to make it work.
I am aware of two implementations (there's maybe more): One by Derivo (your link) and another one by Pellet.

I used OWL-API with Hermit and Pellet; both worked fine. The advantage of Pellet over Hermit is that it supports built-ins.
i.e. In Pellet, for some class Teenager, you can get seventeen year old persons using the following query:
Person and (hasAge value "17.0"^^double)
If you (or somebody) are still interested in, I can provide the Java class for it.

A pure OWL-API-impl cannot provide non-workaround way to support SPARQL since it is not graph based solution.
Now, starting v5, there is ONT-API which is jena-based OWL-API impl.

Related

#PathParam Vs #QueryParam vs #MatrixParam

I am newbie in RESTful jersey.
I would like to ask what is the different among '#PathParam' Vs '#QueryParam' vs '#MatrixParam' in jersey?.
Can't help you with the #MatrixParam but can give you an answer for the other two:
#PathParam: you use placeholder in the path. For example: #Path("/demo/{id}"). In this case the {id} part is your placeholde which you get with #PathParam("id")
#QueryParam: you use the normal uri query Syntax. For example: google.com?q=searchquery which translates to: #QueryParam("q") in your application

How do you do pagination in GUN?

How do you do something like gun.get({startkey, endkey}) ?
Previously: https://github.com/amark/gun/issues/479
#qwe123wsx #sebastianmacias apologies for the delay! Originally posted at: https://github.com/amark/gun/issues/479
The wire spec has a protocol for this but it isn't implemented yet. It looks something like this:
gun.on('out', {get: {'#': {'>': 'a', '<': 'b'}}});
However this doesn't work yet. I would recommend instead:
(1) Pagination behavior is very different from one app to another and will be hard for us to create a "one-size-fits-all" solution, so it would be highly helpful if you could implement your own* pagination and make it available as a user-module, then we can learn from your experience (what worked, what didn't) and make the best solution part of core.
(2) Your app will probably work fine without pagination in the meanwhile, while it can be built (it is targeted for after 1.0), and then as your app becomes more popular, it should be fairly easy to add in without much refactor, once you need it and it is available.
... * How to build your own?
Lots of good articles on this, best one I've seen yet is from Neo4j on how to do it in a graph database (which applies to gun as well) https://graphaware.com/neo4j/2014/08/20/graphaware-neo4j-timetree.html .
Another rough idea is you model your data based on pagination or time. So rather than having ALL tweets go into user's tweet table, instead, the user's tweet table is a table of DAYS (or weeks), and then you put the tweet inside the week table. Now when you load the data, you can scan/skip based off of week very easily while it being super bandwidth efficient.
Rough PSEUDO code:
function onTweetSend(tweet){
gun.get('user').get('alice').get('tweets').get(Date.uniqueYear() + Date.uniqueWeek()).set(tweet)
}
function paginateUserTweet(howMany, cb){
var range = convertToArrayOfUniqueWeekNamesFromToday(howMany);
var all = [];
range.forEach(function(week){
gun.get('user').get('alice').get('tweets').get(week).load(function(tweets){
all.push(tweets);
if(all.length < range.length){ return }
all = flattenArray(all);
cb(all);
});
});
}
Now we can use https://gun.eco/docs/RAD#lex
gun.get(...).get({'.': {'>': startkey, '<': endkey}, '%': 50000}).map().once(...)

How to compare values, ignoring diacritics, with SPARQL

I've been trying (with no success so far) to filter values with a "broader equals" condition. That is, ignoring diacritics.
select * where {
?s per:surname1 ?t.
bind (fn:starts-with(str(?t),'Maria') as ?noAccent1) .
bind (fn:translate(str(?t),"áéíóú","aeiou") as ?noAccent2) .
} limit 100
To this moment, I've tried with XPath functions fn:contains, fn:compare, fn:translate, fn:starts-with, but none of them seem to be working.
Is there any other way (other than chaining replaces) to add collation into these functions or achieve the same goal?
The XPath functions you mention are not part of the SPARQL standard really, so as you found out, you can't rely on them being supported out of the box (though some vendors may provide them as an add-on).
However, GraphDB (which is based on RDF4J) allows you to create your own custom functions in SPARQL. It is a matter of writing a Java class that implements the org.eclipse.rdf4j.query.algebra.evaluation.function.Function interface, and registering it in the RDF4J engine by packaging it as a Java Service Provider Interface (SPI) implementation.
SPARQL and REGEX do not support efficiently transliterating character maps. If you want an efficient implementation you would need a custom RDF4J custom as described by Jeen.
If you want a quick and dirty solution use this code sample:
PREFIX fn: <http://www.w3.org/2005/xpath-functions#>
PREFIX spif: <http://spinrdf.org/spif#>
select * where {
BIND("Mariana" as ?t) .
BIND("Márénísótú" as ?t2) .
BIND (regex(str(?t),'^Maria') as ?noAccent1) .
BIND (spif:replaceAll(
spif:replaceAll(
spif:replaceAll(
spif:replaceAll(
spif:replaceAll(str(?t2),"á","a"),
"é","e")
,"í","i"),
"ó","o"),
"ú","u") as ?noAccent2) .
}

How to use query.filter and .filter_by in SQLAlchemy?

With Django it is possible to find models using the filter method with keyword-arguments like so:
MyModel.objects.filter(serialNo_gt=10)
giving all models with a serial number greater than 10.
Is it possibly to use a similar query language with sql-alchemy? I know that one can write something like MyModel.seriealNO < 10, but with that the code that uses this construct need to import MyModel and I want to create the keywords/query parameters externally without importing MyModel (for a facade-pattern).
the concept of "<attributename>_<operatorname>=<value>" is not built in to SQLAlchemy's Query, however the effect is very easy to reproduce. Here's a quick example done by the author of Flask: https://github.com/mitsuhiko/sqlalchemy-django-query/blob/master/sqlalchemy_django_query.py

nHibernate 3.0 queries

Working through the summer of nHibernate tutorials have gotten to the section on queries. Seems there have been changes since that series was made. So I went to the online docs for nHB 3.0 but code such as:
IList cats = session.CreateCriteria(typeof(Cat))
.Add(Expression.Like("Name", "Fritz%"))
.Add(Expression.Between("Weight", minWeight, maxWeight))
.List();
Generates the error "The name 'Expression' does not exist in the current context"
Code like:
return session.CreateCriteria(typeof(DataTransfer.Customer))
.Add(new NHibernate.Criterion.LikeExpression("Firstname", firstname))
.Add(new NHibernate.Criterion.LikeExpression("Lastname", lastname))
.List<Customer>();
Works but it seems that it is missing a number of query methods like GtExpression.
Are the online docs up to date, and if so, why can't I use Expression...
If the online docs aren't up to date then where do I get a description of the Criterion interface?
Thanks
You forgot to add using NHibernate.Criterion;.
Anyway, the Expression class is deprecated. Use Restrictions instead.
Weird thing. I still use Expression.* static methods and these are still work. Are you sure you use the latest version of NH3.0? I use Alpha 2 version.
If you need to make it work urgently, let's try the QueryOver<> feature:
return session.QueryOver<DataTransfer.Customer>()
.WhereRestrictionOn(u => u.Name).IsLike("Fritz%")
.AndRestrictionOn(u => u.Weight).IsBetween(minWeight).And(maxWeight)
.List();
It works well for simple queries