Updating datatype property value base on SWRL rules - sparql

Hi i have made an ontology in protege 4.3 for users , suppose 1 of my ontology subclass of class user are:
1-"Interest" , and class "interest" have subclasses: "onlineGaming","onlineMovie","onlineshoping",... and every subclass has individual: everyday,onceAweek,onceAmonth)
and i have 3 datatype property for every user: (internetspeed,internetTraffic,Price)
data gathered based on a questionnaire
i just need to infer from this ontology how important this 3 datatype property factors is for internet users
i need to make some SWRL rules in protege to Infer user interest weight , for example if a user do onlineMovie everyday add a +3 to internetTraffic dataproperty.
user(?u) ^ hasOnlineMovieInterest(?u , everyday)-> add +3 to user(?u,InternetTraffic)
user(?u) ^ hasOnlineGamingInterest(?u , OnceAweek) and hasOnlineMovieInterest(?u , everyday)-> add +2 to user(?u,internetSpeed)
how should i write this properly in SWRL rules?
and my second question is how can i have the value of this 3 datatype property for every user in sparql and save the result?
Thanks for your help

First of all; it is not clear what you are doing / which technology using, etc., please consider clarifying your question. Moreover, the conceptual made you developed doesn't seem sound. Are you sure this is the best way to represent the information you want? For example, why would a UserInterest be a subClassOf User? I think you mean that UserInterest and UserInterestRate are ranges for an object property that connect User to them, i.e., hasInterest rdfs:domain User and hasInterest rdfs:range UserInterest.
Coming to your questions, do you use Protege? If you use it you can implement these SWRL rules using the SWRL tab in Protege.
After you have implemented this correctly, you can simply use some SPARQL query similar to:
select ?user ?r1 ?r2 ?r3 Where {
?user rdf:type yourNamespacePrefix:User.
?user yourNamespacePrefix:rate1 ?r1.
?user yourNamespacePrefix:rate2 ?r2.
?user yourNamespacePrefix:rate3 ?r3.
}

Related

sparql query to get all individual of specific class using data value

I have an ontology that contains two classes (course,lesson) the course has a data properties called code of type string
How to get all individuals from specific class with specific data properties value
here is a screenshot
The general pattern is something like this:
SELECT ?individual
WHERE { ?individual a <uri-of-specific-class> ;
<uri-of-property> ?propertyValue .
FILTER(STR(?propertyValue) = "expected value")
}
You will need to adapt this with the details of your specific ontology (the URIs of your class names and properties), but it shows the general approach. I would also suggest that you try out a SPARQL tutorial, there's several good ones online for you to find.

combining datatype and objectype properties OWL

I want to combine the instance (results) associated with two different property types. I can combine them using SPARQL, but I would like to define it the model itself. I am not sure what is the best way to accomplish it. Let me provide you a concrete example.
I have two classes (:book, :tag), an objecttype property (:hasTag), and a datatype property (:hasDescription) with strings.
Instances are defined as:
:book1 a :book .
:semantics a :tag .
:book1 :hasTag :semantics .
:book1 :hasDescription "book about web technology" .
:book1 :hasDescription "good for all level of users" .
:book1 :hasDescription "has examples from biomedical industries" .
There are other classes and properties as well. I would like to get the tag results (semantics) and description results ("book about web technology", "good for all level of users", "has examples from biomedical industries") for book1. Can it be done be defining another property and somehow linking the new property to hasTag and hasDescription ? or is there another/better way?
Also, on a separate note, I am assuming that two instances to a datatype property (as I did in the example) is fine. Please let me know if there are any concerns in this case.

Create and connect individuals with an OWL DL reasoner

I have an ontology with different type of events.
Therefore I have three classes: A, B, C and a helper class Temp.
I want the reasoner to create a new individual as a subclass of C for every pair of individuals a (rdf:typeOf A) and b (rdf:typeOf B) found. This new Individuals should contain informations about a and b.
In the past I used a jena reasoner with an own rule file to get this result, but now I want to switch over to a standard OWL DL reasoner.
My initial idea is to link a und b such as:
a onto:hasB b
And ad give a the Type Temp with the following restriction for Temp:
hasbB some B
Now I want to create a new individual of type C with a restriction for Temp:
hasC some C
And over this new indivual I can access the informations of a and b.
My Problems are:
How can I get the reasoner to connect a and b?
I don't think the creation of C will work, since its a restriction for Temp, which will never be assigned as a type because of this restriction.
Or am I completly wrong with my approach?
Edit:
To clarify my goal with a better exmple:
I have an ontology with different type of events.
My goal is to connect certain individuals (events) which belong together by forming a new individual (event) describing this relation with the help of a reasoner.
E.g.:
I read an event (individual) which describes an "Alarm" (type) into the ontology.
I read an event (individual) which discribes a "PowerOutage" (type) into the ontology.
These Individuals aren't related at all at this moment.
Now I want a reasoner to create a new event (individual) with the type "PowerManipulation". In fact I want an individual with the type "PowerManipulation" created for every pair (which isn't connected, yet) of individuals with the type "PowerOutage" and "Alarm" found. These new individuals should have references (properties) to the individual which caused their creation (an "Alarm" and a "PowerOutage").
Ontology before the reasoning:
(alarm1 rdf:type "Alarm")
(out1 rdf:type "PowerOutage")
What I want the ontology to look like after the reasoning
(alarm1 rdf:type "Alarm")
(out1 rdf:type "PowerOutage")
(man1 rdf:type "PowerManipulation")
(man1 ont:hasRealtadInd alarm1)
(man1 ont:hasRealtedInd out1)
Priviously I used Jena rules and the Jena reasoner to accomplish this task.
But I want to switch over to a standard OWL DL reasoner.
Is it possible to accomplish this task with basic restrictions?
Or do I need SWRL rules, or SPIN (see Williams answer below)?
You can do this with SPIN constructors quite easily and SPIN inserts.
http://www.w3.org/Submission/2011/SUBM-spin-modeling-20110222/#spin-rules-construct
http://www.w3.org/Submission/2011/SUBM-spin-modeling-20110222/#spin-rules-update
SPIN and OWL can live happily together. Take a look at the groovy library that has extensions for both:
https://github.com/williamgreenly/lescot
Example below:
def model = new GroovyRdfModel()
model.add(""" some turtle data """)
model.add(""" some OWL rules """)
model.add(""" some SPIN rules """)
def inferredModelByOWLReasoning = model.owl()
def inferredModelBySPINRules = model.spin()

Fashion related content queries (DBpedia or Freebase)

I'm trying to figure out how to make some queries through which I should get fashion related content, like an list of known cloth types, or cloth manufactures, or well known fashion designers.
I have spent the last few days trying to figure out to make such an query through DBpedia or Freebase, but I couldn't seem to figure it out. Examples that kinda match what I need I couldn't find...
Can someone help me with this, some short example on which I can start to work on or some tutorials that explain how can I achieve something like this?
Thank you
Later Edit
I have also found that DBpedia contains an ontology property "dressCode" and I've found these pages: http://en.wikipedia.org/wiki/Dress_code_(Western) and http://en.wikipedia.org/wiki/Dress_code which lists some basic dress codes, like "Formal", "Casual"...
Now my idea is to get properties from each one of these sub-categories (or what they are defined as on DBpedia, as I see they differ from one other).
Any suggestion on how to do this ?
Later Edit
I have managed to make some queries to display some information that could actually help me:
SPARQL - list of social events
SELECT DISTINCT (?label as ?sub)
WHERE {
{
?sub skos:broader <http://dbpedia.org/resource/Category:Social_events> .
?sub rdfs:label ?label.
OPTIONAL {?subsub dcterms:subject ?sub}
}
}
SPARQL - list of dress codes
SELECT DISTINCT (?label as ?dressCode)
WHERE {
{
?dressCode dcterms:subject <http://dbpedia.org/resource/Category:Dress_codes> .
?dressCode rdfs:label ?label.
filter(langMatches(lang(?label),"EN"))
}
}
Now I would like to retrieve the "subject of" for each dress code so that I can connect somehow the dress codes to the social events, but I'm having issues to do that.
Later Edit
I got to the conclusion that I can't find an ontology that actually matches my needs. Basically I need to get cloth properties based on event types so I can make cloth recommendations. Except the restrictions from the event types I also want to add other properties like the current fashion trend, the season in which the event will take place, geo-location (if possible), and other small details like these.
Now I'm trying to use existing ontologies and data that exists on DBpedia & Freebase, like: 'Dress code', 'Event type', 'Colors', 'Fashion designer', 'Fabric', 'Texture', 'Manufacturer', 'Size' and combine them into an ontology which I can actually use in my project to actually make cloth recommendations.
Can anyone help me with some guidelines on how I can do this ? I tried to use Protege to combine some ontologies and extend them after that, but finally I failed to do this.
May be one of the first places you can start with is the DBpedia ontology. When I search for keywords like Fashion, I can see that there are classes like FashionDesigner. So I can check about about the information about fashion designers in DPpedia with a simple SPARQL query like the following using the DPpedia public SPARQL endpoint.
(a) a list of fashion designers:
select distinct ?fashionDesigner
where {
?fashionDesigner a dbpedia-owl:FashionDesigner
}
LIMIT 100
(b) what are the information generally available about a fashion designer
select distinct ?property
where {
?fashionDesigner a dbpedia-owl:FashionDesigner;
?property ?value .
}
I can also select one of the results of query (a) such as Donna Karan take a look what kind of information she has.
So now, my task is to see who the well-known fashion designers. I don't know much about fashion but I see some of them have awards. So I can query for the fashion designers who have won awards.
(c) Fashion designers who have won awards
select distinct ?fashionDesigner ?award
where {
?fashionDesigner a dbpedia-owl:FashionDesigner;
dbpprop:awards ?award .
}
I was only using very basic SPARQL queries but you can use more complex queries when you get to know more about the fashion related concepts and properties in the data.
You can follow a similar approach for classes such as LineOfFashion, Clothing, etc.
For example
(d) a list of clothing manufactures
select distinct ?company where {
?company dbpedia-owl:product dbpedia:Clothing;
dcterms:subject category:Clothing_brands .
} LIMIT 100
The more you explore, you can build better queries. I hope this will help you to get started.
Here's a query that returns award winning fashion designers from Freebase: https://www.googleapis.com/freebase/v1/search?limit=10&scoring=entity&filter=(all+type%3A%2Faward%2Faward_winner+notable%3A%22fashion+designer%22)&lang=en&indent=true
There's a little on-line utility that you can use to experiment with this and check out some of the other items that you were interested in:
http://freebase-search.freebaseapps.com/?filter=(all+type%3A%2Faward%2Faward_winner+notable%3A%22fashion+designer%22)&limit=10&scoring=entity&lang=en

How to use CONSTRUCT / WHERE in a SPARQL SPIN rule declaration

Summary
Thank you in advance for helping me write a CONSTRUCT/WHERE statement that can be declared as a SPIN Rule in TopBraid Composer Free Edition and used.
I am trying to embed a SPARQL CONSTRUCT/WHERE statement in a spin:rule declaration and then execute it. I am returning zero inferences to Statements 1 or 2 below. I am using Java 7, and Eclipse 4.3., and TopBraid Composer Free Edition. I have been successful running Statement 3 as a SPIN Constructor Declaration in the classes form (Statement 3). I have been successful running Statement 4 in the SPARQL query editor (interpreter) I have cross-posted to the user forum.
Details
Fact 1: I have not been able to run Statement 1 as a SPIN Rule.
----Statement 1---
CONSTRUCT {
?this owl:hasKey ?x .
}
WHERE {
BIND (spif:generateUUID() AS ?x) .
}
Fact 2: I have not been able to run Statement 2 as a SPIN Rule.
----Statement 2----
CONSTRUCT {
?this owl:hasKey ?x .
}
WHERE {
?this rdfs:subClassOf node:entity .
BIND (spif:generateUUID() AS ?x) .
}
--No Error Message--
Fact 3: However I have been successful with Statement 3 in the constructor field of the classes form.
----Statement 3----
CONSTRUCT {
?this owl:hasKey ?x .
}
WHERE {
BIND (spif:generateUUID() AS ?x) .
}
Success: When a new instance is created a new triple indicating a key is created.
Fact 4: I have been successful with Statement 4 in the SPARQL query editor which is analogous.
----Statement 4----
CONSTRUCT {
?s owl:hasKey ?x .
}
WHERE {
?s rdf:type node:word_use
BIND (spif:generateUUID() AS ?x) .
}
Success: When statement is run all current instances get keys.
Fact 5: I do not have any SPARQL Rules libraries checked in the Ontology Profile form.
Fact 6: I have imported the following two libraries.
<http://spinrdf.org/spin> from local file TopBraid/SPIN/spin.ttl.
<http://spinrdf.org/sp> from local file TopBraid/SPIN/sp.ttl
Fact 7: The namespaces in the file are:
Base URI (Location) - http://example.org/
Default Namespace - http://example.org/
But the Base URI keeps getting reset to:
http://www.semanticweb.org/owl/owlapi/turtle
ace_lexicon - http://attempto.ifi.uzh.ch/ace_lexicon#
arc - http://example.org/arc#
arg - http://spinrdf.org/arg#
concept - http://example.org/concept#
node - http://www.example.org/node#
owl - http://www.w3.org/2002/07/owl#
rdf - http://www.w3.org/1999/02/22-rdf-syntax-ns#
rdfs - http://www.w3.org/2001/01/rdf-schema#
skos - http://www.w3.org/2004/02/skos/core#
sp - http://spinrdf.org/sp#
spif - http://spinrdf.org/spif#
spin - http://spinrdf.org/spin#
spl - http://spinrdf.org/spl#
word_sense - http://example.org/word_sense#
word_term - http://example.org/word_term#
word_use - http://example.org/word_use#
Fact 8: The class that I am using has the following assertions.
Name - node:unclassified_concept
SubClassOf - node:entity
Fact 9: An instance of the node:unclassified_concept class is described below.
URI - http://example.org/concept#regardless_of1
rdfs:comment - without attention to
rdfs:isDefinedBy - <http://en.wiktionary.org/wiki/regardless_of>
rdfs:label - regardless of
Fact 10: I have been successful using Jena Generic Rules reasoning as well as the OWL_MEM_RULE_INF OntModelSpec, reading/writing, base models, inf models, and ont models.
Context
The context of my problem is the following. I am building and iteratively executing an ontology and rule set using Java and Jena to prove the concept of OWL/RDF representing, considering, and responding to non-trivial type-written English. The sentence I am using is non-trivial (41 words, three clauses, etc.). The current ontology has 1422 assertions when not run against any OWL/RDF rules (transitivity, etc.). I am using TopBraid Composer when possible to complement Jena programming to make sure I am compliant with conventions and standards.
This post outlines the solution to the problem I posted. I was able to come to this solution via a person who responds to their user forum. https://groups.google.com/forum/#!forum/topbraid-users
The CONSTRUCT/WHERE statement (after revision) I wanted to run was:
CONSTRUCT {
?this owl:hasKey ?x .
}
WHERE {
?this rdf:type node:unclassified_concept .
BIND (spif:generateUUID() AS ?x) .
}
However, if I placed this statement in the spin:rule field of the classes form in TBC and pressed the icon for inferencing, I would receive no inferences and much time would be spent churning by the inferencer.
The solution was to create a subproperty of spin:rule that had spin:rulePropertyMaxIterationCount set to 1 (to avoid infinite loops generated by running the built-in function -- in my case spin:generateUUID().)
Then I needed to "pull" or place that new subproperty (which I named "runOnce") into the classes form that I was trying to create a dependent-upon-a-built-in CONSTRUCT/WHERE rule for.
Finally, in the classes form I needed to select add blank row on the new subproperty RunOnce, and then enter my original CONSTRUCT/WHERE statement there.
Then I ran inferencing and the class used the rule.
In short, if you want to embed a rule in a class in TBC, and that rule uses a builtin function, you need to
-Create a subproperty of spin:rule that has rulePropertyMaxIterationCount
set to 1.
-Include this subproperty in the classes form.
-Embed your CONSTRUCT/WHERE statement that uses the built-in within that
subproperty on the classes form by selecting insert blank line and
copying/pasting it in there.
Note the TBC supported SPIN built-in functions is a smaller set than I believe is in the SPIN API documentation. The list of TBC supported built-ins is here in the TBC product.
Help>
Help Contents>
TopBraid Composer>
Application Development Tools>
SPARQL Motion Scripts>
SPARQL Motion Functions Reference
Hope this helps someone.