Find naerby location with SWRL or SPARQL rule

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Find naerby location with SWRL or SPARQL rule

Talya
Hello everyone,

I have created an ontology with Time, Location and Person concepts and with
Longitude, latitude and altitude sub-concepts. and I have a relation between
person and Location (has-longitude, has-latitude, has-altitude) and between
person and Time (has-time). I want to know the nearby location of a Person X
which is located-in Location Y at Time T.

I don't know how to do this, I try to use SWRL and SPARQL to do this but I
do not succeed. Please can anyone have any idea about how doing this?

Thank you very much



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: Find naerby location with SWRL or SPARQL rule

Martin O'Connor-2

I am not sure I understand the question. By 'nearby' do you mean 'nearest'?

If so, you are attempting to perform closed world reasoning, which SWRL (and OWL) will not support.

See: 


Martin

On Oct 28, 2017, at 2:01 PM, Talya <[hidden email]> wrote:

Hello everyone,

I have created an ontology with Time, Location and Person concepts and with
Longitude, latitude and altitude sub-concepts. and I have a relation between
person and Location (has-longitude, has-latitude, has-altitude) and between
person and Time (has-time). I want to know the nearby location of a Person X
which is located-in Location Y at Time T.

I don't know how to do this, I try to use SWRL and SPARQL to do this but I
do not succeed. Please can anyone have any idea about how doing this?

Thank you very much



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user


_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: Find naerby location with SWRL or SPARQL rule

samsontu
In reply to this post by Talya
You have to be more specific about your ontology and what you mean by “nearby location.”

It would be helpful to post your ontology.

With best regards,
Samson


On Oct 28, 2017, at 2:01 PM, Talya <[hidden email]> wrote:

Hello everyone,

I have created an ontology with Time, Location and Person concepts and with
Longitude, latitude and altitude sub-concepts. and I have a relation between
person and Location (has-longitude, has-latitude, has-altitude) and between
person and Time (has-time). I want to know the nearby location of a Person X
which is located-in Location Y at Time T.

I don't know how to do this, I try to use SWRL and SPARQL to do this but I
do not succeed. Please can anyone have any idea about how doing this?

Thank you very much



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

-- 
Samson Tu                                                      email: [hidden email]
Senior Research Engineer                              web: www.stanford.edu/~swt/
Center for Biomedical Informatics Research  phone: 1-650-725-3391
Stanford University                                          fax: 1-650-725-7944




_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: Find naerby location with SWRL or SPARQL rule

Talya
In reply to this post by Martin O'Connor-2
Hello,

Thank you, yes I mean by "nearby" the "nearest Location".

Mr Martin you tell me to perform closed world reasoning which is not
supported with SWRL (and OWL). In fact, I find this link where with geonames
ontology it was possible to express this with spatial:nearby. But  I'm not
sure that is useful in my case.

https://stackoverflow.com/questions/30765893/sparql-query-on-geonames-ontology-using-nearby
<https://stackoverflow.com/questions/30765893/sparql-query-on-geonames-ontology-using-nearby>  

Mr Samson you find attached a small version of my ontology. As example, I
want to know the nearest location to Paris is it Bourges or chirac?

Thank you again for your help
Location.owl
<http://protege-project.136.n4.nabble.com/file/t376164/Location.owl>  



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: Find naerby location with SWRL or SPARQL rule

samsontu
Hi,

Computing the distance between two points using longitude and latitude data requires the use of trig functions that neither SWRL nor SPARQL supports.Unless you can augment your SPARQL engine with such functions, you’d best compute the distances externally. If you know the distance between two locations, you can use SPARQL’s min operator to query for location whose distance to Paris is the minimum of all known locations.

With best regards,
Samson

On Oct 30, 2017, at 9:01 AM, Talya <[hidden email]> wrote:

Hello,

Thank you, yes I mean by "nearby" the "nearest Location".

Mr Martin you tell me to perform closed world reasoning which is not
supported with SWRL (and OWL). In fact, I find this link where with geonames
ontology it was possible to express this with spatial:nearby. But  I'm not
sure that is useful in my case.

https://stackoverflow.com/questions/30765893/sparql-query-on-geonames-ontology-using-nearby
<https://stackoverflow.com/questions/30765893/sparql-query-on-geonames-ontology-using-nearby>   

Mr Samson you find attached a small version of my ontology. As example, I
want to know the nearest location to Paris is it Bourges or chirac?

Thank you again for your help
Location.owl
<http://protege-project.136.n4.nabble.com/file/t376164/Location.owl>  



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

-- 
Samson Tu                                                      email: [hidden email]
Senior Research Engineer                              web: www.stanford.edu/~swt/
Center for Biomedical Informatics Research  phone: 1-650-725-3391
Stanford University                                          fax: 1-650-725-7944




_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: Find naerby location with SWRL or SPARQL rule

suryawanshiyogitas@gmail.com
In reply to this post by Talya
Hello,
You can try to use GeoSPARQL ontology as a top level ontology for your
ontology. This will enable you to directly use geo:distance() function of
GEOSPARQL.

If you still wish to continue with your own ontology may be the below
stackoverflow link you can refer. I tried to write this using SPARQL but it
was really complex. Upvote it if you find useful!

https://stackoverflow.com/questions/43250786/how-to-use-geofdistance-function-from-geosparql


Regards,
ysg



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: Find naerby location with SWRL or SPARQL rule

Martin O'Connor-2
In reply to this post by samsontu

The SWRLAPI has a mathematical built-in that allows the use of relatively complex mathematical expressions, e.g.,

 Person(?p1) ^ Person(?p2) ^ differentFrom(?p1,?p2) ^
    hasX(?p1,?x1) ^ hasY(?p1,?y1) ^ hasX(?p2,?x2) ^ hasY(?p2,?y2) ^
    swrlm:eval(?d, "sqrt(pow(x1-x2, 2) + pow(y1-y2, 2))", ?x1, ?y1, ?x2, ?y2)
    -> sqwrl:select(?p1, ?p2, ?d) 



Martin

On Oct 30, 2017, at 5:03 PM, Samson Tu <[hidden email]> wrote:

Hi,

Computing the distance between two points using longitude and latitude data requires the use of trig functions that neither SWRL nor SPARQL supports.Unless you can augment your SPARQL engine with such functions, you’d best compute the distances externally. If you know the distance between two locations, you can use SPARQL’s min operator to query for location whose distance to Paris is the minimum of all known locations.

With best regards,
Samson

On Oct 30, 2017, at 9:01 AM, Talya <[hidden email]> wrote:

Hello,

Thank you, yes I mean by "nearby" the "nearest Location".

Mr Martin you tell me to perform closed world reasoning which is not
supported with SWRL (and OWL). In fact, I find this link where with geonames
ontology it was possible to express this with spatial:nearby. But  I'm not
sure that is useful in my case.

https://stackoverflow.com/questions/30765893/sparql-query-on-geonames-ontology-using-nearby
<https://stackoverflow.com/questions/30765893/sparql-query-on-geonames-ontology-using-nearby>   

Mr Samson you find attached a small version of my ontology. As example, I
want to know the nearest location to Paris is it Bourges or chirac?

Thank you again for your help
Location.owl
<http://protege-project.136.n4.nabble.com/file/t376164/Location.owl>  



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user

-- 
Samson Tu                                                      email: [hidden email]
Senior Research Engineer                              web: www.stanford.edu/~swt/
Center for Biomedical Informatics Research  phone: 1-650-725-3391
Stanford University                                          fax: 1-650-725-7944



_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user


_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: Find naerby location with SWRL or SPARQL rule

Talya
Thank you very much for your answers suryawanshiyogitas, Martin and samsontou. Sir Martin as you say that we can calculate the distance between two points, and I think that with SQWRL:OrderBy and SQWRL:limit, we can return the nearest location to person. The SQWRL query looks like this: Person(?p1) ^ Person(?p2) ^ differentFrom(?p1,?p2) ^ hasX(?p1,?x1) ^ hasY(?p1,?y1) ^ hasX(?p2,?x2) ^ hasY(?p2,?y2) ^ swrlm:eval(?d, "sqrt(pow(x1-x2, 2) + pow(y1-y2, 2))", ?x1, ?y1, ?x2, ?y2) -> sqwrl:select(?p1, ?p2, ?d) ^ sqwrl:OrderBy(?d) ^ sqwrl:limit(1) I think it is true but I do not try it.

Sent from the Protege User mailing list archive at Nabble.com.

_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: Find naerby location with SWRL or SPARQL rule

Martin O'Connor-2

Yes - you could use SQWRL's orderBy and limit operators to sort by distance and then pick the lowest.

Note that this type of closed world operation is only possible when querying. You cannot make inferences based on the answer. 

Martin

On Nov 8, 2017, at 1:10 PM, Talya <[hidden email]> wrote:

Thank you very much for your answers suryawanshiyogitas, Martin and samsontou. Sir Martin as you say that we can calculate the distance between two points, and I think that with SQWRL:OrderBy and SQWRL:limit, we can return the nearest location to person. The SQWRL query looks like this: Person(?p1) ^ Person(?p2) ^ differentFrom(?p1,?p2) ^ hasX(?p1,?x1) ^ hasY(?p1,?y1) ^ hasX(?p2,?x2) ^ hasY(?p2,?y2) ^ swrlm:eval(?d, "sqrt(pow(x1-x2, 2) + pow(y1-y2, 2))", ?x1, ?y1, ?x2, ?y2) -> sqwrl:select(?p1, ?p2, ?d) ^ sqwrl:OrderBy(?d) ^ sqwrl:limit(1) I think it is true but I do not try it.

Sent from the Protege User mailing list archive at Nabble.com.
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user


_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: Find naerby location with SWRL or SPARQL rule

Talya
Good Day,

Ok Sir.

So to make inference is it possible to create a custom builtin that allow to
calculate the distance between two GPS points and then return the list of
nearest location.


Thank you



--
Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user
Reply | Threaded
Open this post in threaded view
|

Re: Find naerby location with SWRL or SPARQL rule

Martin O'Connor-2

While you could implement such a built-in, all inferences made with it would be outside the semantics of OWL and SWRL.

OWL and SWRL support monotonic inference only. They are not designed for the types of inferences you require.

Since new locations could (presumably) be added to your ontology, it is easy to see that nearest locations can change non-monotonically.

Martin

> On Nov 9, 2017, at 12:38 AM, Talya <[hidden email]> wrote:
>
> Good Day,
>
> Ok Sir.
>
> So to make inference is it possible to create a custom builtin that allow to
> calculate the distance between two GPS points and then return the list of
> nearest location.
>
>
> Thank you
>
>
>
> --
> Sent from: http://protege-project.136.n4.nabble.com/Protege-User-f4659818.html
> _______________________________________________
> protege-user mailing list
> [hidden email]
> https://mailman.stanford.edu/mailman/listinfo/protege-user


_______________________________________________
protege-user mailing list
[hidden email]
https://mailman.stanford.edu/mailman/listinfo/protege-user