Rules for the Semantic Web Dipartimento di Informatica, Sistemistica e Comunicazione Università di Milano-Bicocca
[email protected]
[email protected] [email protected] [email protected]
tel. 02 6448 7835 tel. 02 6448 7879
Semantic Web I have a dream for the Web [in which computers] become capable of analyzing all the data on the Web – the content, links, and transactions between people and computers. A ‘Semantic Web’, which should make this possible, has yet to emerge, but when it does, the day-to-day mechanisms of trade, bureaucracy and our daily lives will be handled by machines talking to machines. The ‘intelligent agents’ people have touted for ages will finally materialize. Tim Berners-Lee, 1999
Semantic Web Layer Cake User Interface & Applications
today:
SWRL (Semantic Web Rule Language)
tomorrow: Rule Interchange Format Working Group RIF (Rule Interchange Format)
Unifying logic
OWL Reasoning Cart #1
hasPrice
contains
320€
contains contains
Item #1
Item #2
hasPrice 100€
Item #3 hasPrice
hasPrice 150€
70€
• “The total price is the sum of the price of the items in the cart” • OWL lacks of support for this kind of reasoning !
SWRL (Semantic Web Rule Language) SWRL is a a rules-language, combining OWL (Lite or DL) with RuleML (Rule Markup Language)
OWL (Lite/DL)
RuleML
SWRL
Example (human readable) hasPrice(?x1,?p1)
hasPrice(?x2,?p2)
lessThan (?p1,?p2)
isCheaper(?x1,?x2)
http://www.w3.org/Submission/SWRL/
Timeline DLV is a Disjunctive Datalog System
CLIPS is a software tool for building expert systems. The name is an acronym for "C Language Integrated Production System." The first versions of CLIPS were developed starting in 1985 at NASA-Johnson Space Center
DLV
SWRL
1997
2004
Prolog is a general purpose logic programming language
CLIPS Prolog
1985
Semantic Web Rule Language
1995
2001 RuleML
Jess
1972 1980
Datalog is a subset of Prolog. It is a query and rule language for deductive databases
Datalog
Jess, a rule engine for the Java platform
The Rule Markup Initiative has taken steps towards defining a shared Rule Markup Language, permitting both forward and backward rules in XML
Decidability Decidability: Terminates after a finite amount of time and correctly decides
OWL (Lite/DL)
RuleML
SWRL Decidability ?
No
SWRL Alternative: DLP
OWL
DLP
Logic Programing (Datalog)
Decidability ?
YES
Datalog rules
facts Example Datalog program:
facts
parent(bill,mary). parent(mary,john).
rules
ancestor(X,Y) :- parent(X,Y). ancestor(X,Y) :- ancestor(X,Z),ancestor(Z,Y).?-
Datalog Engine
Query: ?- ancestor(bill,X).
ancestor(bill,mary). ancestor(bill,john).
query
result
RuleML (Rule Markup Language) • RuleML is a family of languages developed to express both forward and backward rules in XML for deduction, rewriting, and further inferential-transformational tasks • Example: XSLT (Extensible Stylesheet Language Transformations) is a restricted termrewriting system of rules, written in XML, for transforming XML documents into other documents http://www.ruleml.org/
SWRL Rule Example hasPrice(?x1,?p1)
hasPrice(?x2,?p2)
lessThan (?p1,?p2)
isCheaper(?x1,?x2)
In the abstract syntax the rule would be written like: Implies ( Antecedent( hasPrice(I-variable(x1) I-variable(p1)) swrlb: hasPrice(I-variable(x2) I-variable(p2)) namespace for the swrlb:lessThan(I-variable(p1) I-variable(p2))) SWRL Built-ins
Consequent( isCheaper(I-variable(x1) I-variable(x2))))
Rule Example in RDF Concrete Syntax
swrl: namespace for the SWRL
ruleml: namespace for the SWRL Built-ins
RDF Triples...
Architecture from datalog...
...to SWRL rules
facts
SWRL rules
Reasoner + SWRL Engine
Datalog Engine
query
owl (T-Box, A-Box)
result
query
result
SWRL Editor The SWRLTab is a development environment for working with SWRL rules in Protégé. It supports the editing and execution of SWRL rules.
The Protégé distribution does not include any rule engines. At present, only the Jess is supported.
Reasoner Pellet is an open source OWL Reasoner and SWRL Engine
http://pellet.owldl.com/
Search RDF Data An RDF graph can contains a huge number of statements, but how can you find and manipulate the data you need within RDF graphs?
SPARQL is a query Language for RDF SPARQL is a product of the w3c RDF Data Access Working group (DAWG). 4 core specs:
Current status: proposed recomendation Last revision: 12 november 2007
- SPARQL Query Language for RDF - SPARQL Protocol for RDF - SPARQL Query Results XML Format - RDF Data Access Use Cases and Requirements
http://www.w3.org/2001/sw/DataAccess/
http://www.w3.org/TR/rdf-sparql-query/
What is a Query ? A Query is question. Answering requires understanding: An RDF graph
Data graph
Query graph
SPARQL uses • The query RDF graph for queries • The thing queried • The relationship between them
SPARQL Query Engine
Results (table, boolean)
SPARQL Query Types Ground graphs as queries
Boolean query Returns TRUE if Data Graph => Query Graph ASK WHERE { book:0001 book:author author:01 . }
ASK Other SPARQL query types:
DESCRIBE, CONSTRUCT
Variable
SELECT SELECT ?author WHERE { book:0001 book:author ?author . }
Blank nodes as query variables
There is an answer if data graph query graph
Results is a Table, not a Graph
A simple query Find the URL of the blog by the person named “Jon Foobar”
Data graph
query type (SELECT)
Basic graph structure for a single contributor in bloggers.rdf source: Philip McCarthy
result variable
PREFIX foaf: SELECT ?url WHERE { ?contributor foaf:name "Jon Foobar" . ?contributor foaf:weblog ?url . }
subject
predicate
object (variable)
Query graph in RDF Turtle notation
Results
SPARQL Query
Data graph
One more example @prefix dc: . _:author1 "J.K. Rowling" .
dc:title "Harry Potter and the Chamber of Secrets" . dc:creator _:author1 . dc:title "Harry Potter and the Prisoner Of Azkaban" . dc:creator _:author1 .
PREFIX books: PREFIX dc: PREFIX vcard: SELECT ?bookTitle ?authorName WHERE { ?book dc:creator ?author . ?book dc:title ?bookTitle . ?author vcard:FN ?authorName }
bookTitle
authorName
Harry Potter and the Chamber of Secrets
J.K. Rowling
Harry Potter and the Prisoner Of Azkaban
J.K. Rowling
Try this example online: http://www.sparql.org/query.html
Value constraints ASK WHERE { ?author vcard:FN “J.K. Rowling” . }
This query returns true iff there is an author with name “J.K. Rowling”
SPARQL provides an operation to test strings, based on regular expressions. The syntax is different from the SQL “LIKE” ! ASK WHERE { ?author vcard:FN ?name . FILTER regex(?name, "rowling", "i") }
Filter Pattern ASK WHERE { person:0001 info:age ?age . FILTER (?age >= 18) }
This query returns true iff an author names contains the string “rowling” Filter flags: “i” means “Case insensitive”
The regular expression language is the XQuery regular expression language which is codified version of that found in Perl.
Filter on an integer property. This query returns true iff there is a person 0001 has age >= 18
http://www.w3.org/TR/xpath-functions/#regex-syntax
http://www.perl.org
Value constraints Filter on the value of an integer property. SELECT ?name ?age WHERE { ?person info:name ?name . ?person info:age ?age . FILTER (?age >= 18) }
This query returns the name and age of each person with age >= 18
SPARQL has a the ability to query for data but not to fail query when that data does not exist. SELECT ?name ?age WHERE { ?person info:name ?name . OPTIONAL { ?person info:age ?age . FILTER ( ?age > 18 ) } }
This query returns the name and age of each person with unknown age or age >= 18
Architecture (revised) Ontology Storage
Ontology Update
owl (T-Box, A-Box)
SWRL rules
Reasoner + SWRL Engine
SPARQL queries
User Interface
SPARQL Engine results
Useful links w3c RDF Data Access Working group: http://www.w3.org/2001/sw/DataAccess/ SPARQL Woking Draft: http://www.w3.org/TR/rdf-sparql-query/ Jena SPARQL tutorial: http://jena.sourceforge.net/ARQ/Tutorial/index.html SPARQL Regular expression: http://www.w3.org/TR/xpath-functions/#regex-syntax Online SPARQL query: http://www.sparql.org/query.html