Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using Semantic Web Data: Inference Lalana Kagal Decentralized Information Group MIT CSAIL Eric Prud'hommeaux Engineer World Wide Web Consortium.

Similar presentations


Presentation on theme: "Using Semantic Web Data: Inference Lalana Kagal Decentralized Information Group MIT CSAIL Eric Prud'hommeaux Engineer World Wide Web Consortium."— Presentation transcript:

1 Using Semantic Web Data: Inference Lalana Kagal Decentralized Information Group MIT CSAIL Eric Prud'hommeaux Engineer World Wide Web Consortium

2 Why do we need Rules on the Web? The Semantic Web provides a unifying representation of richly structured data Adding logic to the Web implies the use of rules to make inferences, choose courses of action, and answer questions This logic must be powerful enough to describe complex properties of objects but not so powerful that agents can be tricked by being asked to consider a paradox

3 N3Logic: A Logic For the Web N3Logic is a logic that allows rules to be expressed in a Web environment. It extends RDF with syntax for –nested graphs –quantified variables –predicates for implication –accessing resources on the Web –functions including cryptographic, string, math The main goal of N3Logic is to be a minimal extension to the RDF data model such that the same language can be used for logic and data

4 N3 Versus N3Logic N3 is a compact and readable alternative to RDF's XML syntax N3 adds quoting to Turtle –Turtle : –N3: { } –Does not imply that N3Logic uses N3 syntax and extends RDF with a vocabulary of predicates N3Logic allows rules to be integrated smoothly with RDF and provides certain essential built-in functions

5 N3Logic Tools N3Logic reasoner – cwm

6 Installing cwm Prerequisites –Python: http://www.python.org/http://www.python.org/ –cwm needs Python2.2 or later Download –http://www.w3.org/2000/10/swap/cwm.tar.gzhttp://www.w3.org/2000/10/swap/cwm.tar.gz Alias to executable –Set up an alias (.bat file, etc) to make the cwm command –In bash this is cwm="python /whereverYouPutThem/cwm.py"

7 Testing cwm At the command prompt > cwm http://dig.csail.mit.edu/2008/Talks/0518-SemTech-eplk/cwm-code/test1.n3

8 Executing Cwm You can get a list of these by typing cwm --help --rdf Input & Output in RDF/XML instead of n3 --n3 Input & Output in N3 from now on (Default)‏ --think as -rules but continue until no more rule matches --filter=foo Read rules from foo, apply to store, replacing store with conclusions Examples –Combine data and find all deductions cwm foo.n3 bar.n3 --think –Convert from rdf/xml to rdf/n3 cwm --rdf foo.rdf --n3

9 If installed correctly At the command prompt > cwm --n3 http://dig.csail.mit.edu/2008/Talks/0518-SemTech-eplk/cwm-code/test1.n3

10 Scenario: Decentralized Access Control The DIG group has several online resources including pictures, papers, presentations, and proposals that are only accessible to members of the group and to people that members trust. The group has a webpage that lists its members using N3. The page identifies members by their Friend Of A Friend (FOAF) pages. Authentication in this scenario is via OpenID. DIG members provide their OpenID URI (usually the same as their work homepages) in their FOAF pages. Open http://dig.csail.mit.edu/2008/Talks/0518-SemTech-eplk/code/data.n3 for this data about the DIG grouphttp://dig.csail.mit.edu/2008/Talks/0518-SemTech-eplk/code/data.n3 Policy: Only group members are allowed to access group resources or people that group members know

11 Scenario: Decentralized Access Control For simplicity, the data that we check our demo policies against also include a test request for a DIG resource :Req1 a air:Request; foaf:openid ; air:resource.

12 N3 Overview (RDF Extension) ‏ Quoted formulae –b:mary says { j:Joe foaf:member :DIG }. Universally quantified formulas –@forAll X. { X a Man } log:implies { X a Mortal }. –shorthand notation ?X { ?X a Man } log:implies { ?X a Mortal }. Existential variables or blank nodes –@forSome :X. j:Joe foaf:knows :X. :X foaf:name "Fred". –shorthand notation j:Joe foaf:knows [ foaf:name "Fred" ].

13 N3 Overview (RDF Extension) ‏ Additional builtins with URI references defined in –log: http:// www.w3.org/2000/10/swap/log# –crypto: http://www.w3.org/2000/10/swap/crypto# –list: http://www.w3.org/2000/10/swap/list# –math: http://www.w3.org/2000/10/swap/math# –os: http://www.w3.org/2000/10/swap/os# –string: http://www.w3.org/2000/10/swap/string# –time: http://www.w3.org/2000/10/swap/time# N3Logic extends RDF with variables and nested graphs to enable the descriptions of rules shorthand notation for log:implies is => { A } => { B } where A and B are sets of triples

14 Developing First Rule RULE: A member of DIG is a user in the memberlist of DIG @forAll :MEMBER. { :DIG foaf:member :MemberList. :MEMBER air:in :MemberList. } => {:MEMBER foaf:member :DIG}.

15 Visualising First Rule Open http://dig.csail.mit.edu/2008/Talks/0518-SemTech-eplk/cwm-code/rule1.n3 in any editor http://dig.csail.mit.edu/2008/Talks/0518-SemTech-eplk/cwm-code/rule1.n3

16 Executing First Rule Execute cwm with rule1.n3 and data.n3 > cwm http://dig.csail.mit.edu/2008/Talks/0518-SemTech-eplk/cwm- code/data.n3 http://dig.csail.mit.edu/2008/Talks/0518-SemTech- eplk/cwm-code/rule1.n3 --think

17 Executing First Rule Produces too much information Need to filter results Only display those results generated by the rule > cwm http://dig.csail.mit.edu/2008/Talks/0518-SemTech-eplk/cwm- code/data.n3 http://dig.csail.mit.edu/2008/Talks/0518-SemTech- eplk/cwm-code/rule1.n3 --think -- filter=”http://dig.csail.mit.edu/2008/Talks/0518-SemTech-eplk/cwm- code/rule1.n3”

18 Executing First Rule

19 Graph Functions access a file and store its N3 representation in a variable – log:semantics check if one formula can be derived from another formula – log:includes scoped negation as failure of log:includes – log:notIncludes thinking inside – log:conclusion Merging a list of formulae –( ) log:conjunction

20 Developing Second Rule Read information from http://dig.csail.mit.edu/2008/Talks/0518- SemTech-eplk/cwm-code/data.n3 Print all instances of foaf:Organizations and their foaf:names

21 Developing Second Rule @prefix log:. @prefix rdfs:. @prefix foaf:. @prefix :. @forAll :F, :G, :N. { log:semantics :F. :F log:includes { :G a foaf:Organization; foaf:name :N }. } => { :G a foaf:Organization; foaf:name :N }.

22 Executing Second Rule Execute this rule and see if it works > cwm http://dig.csail.mit.edu/2008/Talks/0518-SemTech-eplk/cwm- code/rule2.n3 --think --filter="http://dig.csail.mit.edu/2008/Talks/0518-SemTech- eplk/cwm-code/rule2.n3"

23 Executing Second Rule

24 Developing Third Rule Access the data file and see all attributes passed along with the Request A ValidRequest is one that has both the requester's openID URI as well as a requested resource that is a DIG resource

25 Developing Third Rule @forAll :F, :REQ, :REQUESTER, :RESOURCE. { log:semantics :F. :F log:includes { :REQ a air:Request; foaf:openid :REQUESTER; air:resource :RESOURCE }. :F log:includes { :DIG :owns :RESOURCE }. } => { :REQ a air:ValidRequest }.

26 Executing Third Rule

27 Developing Fourth Rule Add another rule to the policy; if the Request is valid, check if the requester is a member of the DIG group If the requester is a member of the DIG group, the request is compatible with the DIGPolicy @forAll :F, :REQ, :REQUESTER, :RESOURCE, :MEMBERLIST, :MEMBER. { log:semantics :F. :REQ a air:ValidRequest. :F log:includes { :REQ foaf:openid :REQUESTER. :DIG foaf:member :MEMBERLIST. :MEMBER air:in :MEMBERLIST. :MEMBER a foaf:Person; foaf:openid :REQUESTER } } => { :REQ air:compatible-with :DIGPolicy }.

28 Executing Fourth Rule > cwm http://dig.csail.mit.edu/2008/Talks/0518-SemTech-eplk/cwm-code/rule4.n3 -- think --filter="http://dig.csail.mit.edu/2008/Talks/0518-SemTech-eplk/cwm- code/rule4.n3"

29 Executing Fourth Rule

30 Developing Fifth Rule –Write a rule that that merges two rules and data –rule1.n3 that infers the list of members of DIG –rule6.n3 that infers that a request is valid if it for a DIG resource and if it includes the openID URI of the requester –data.n3 that includes the data of the DIG group and an example request and uses log:conclusion to think and execute rule1.n3 and rule6.n3 against the data to infer that the request is a PermittedRequest if it is valid and the requester is from the DIG group

31 Developing Fifth Rule @forAll :D, :R1, :R6, :F, :G, :MEMBER, :REQ, :REQUESTER. { log:semantics :D. log:semantics :R1. log:semantics :R6. ( :D :R1 :R6 ) log:conjunction :F. :F log:conclusion :G. :G log:includes { :REQ a air:ValidRequest; air:requester :REQUESTER. :MEMBER foaf:member :DIG. :MEMBER foaf:openid :REQUESTER } } => { :REQ a air:PermittedRequest }.

32 Executing Fifth Rule > cwm http://dig.csail.mit.edu/2008/Talks/0518-SemTech-eplk/cwm-code/rule5.n3 --think --filter="http://dig.csail.mit.edu/2008/Talks/0518-SemTech-eplk/cwm- code/rule5.n3"

33 Executing Fifth Rule

34 More N3Logic Builtins –crypto functions – md5, sign, and verify –math functions- cos, sin, greaterThan, notGreaterThan, and difference –os functions for retrieving environment information – argv, baseAbsolute, and baseRelative –string functions – concatenation, matches, and startsWith –time functions – dayOfWeek, gmTime, and localTime

35 Developing Seventh Rule –Write a rule that when given a temperature in F degrees as a commandline argument, converts it into Celcius degrees –Use os functions to retrieve the commandline argument os:argv arguments passed using “--with” –Use math functions to convert to celcius ( ) math:difference ( ) math:product

36 Developing Seventh Rule @forAll :TF, :T1, :TC. { "1" os:argv :TF. ( :TF 32 ) math:difference :T1. (:T1 "0.5555" ) math:product :TC } => { :TC :tempInCOf :TF }.

37 Executing Seventh Rule > cwm http://dig.csail.mit.edu/2008/Talks/0518-SemTech- eplk/cwm-code/rule7.n3 --think -- filter="http://dig.csail.mit.edu/2008/Talks/0518-SemTech- eplk/cwm-code/rule7.n3" --with 40

38 Cwm Resources Cwm tutorial –http://www.w3.org/2000/10/swap/doc/http://www.w3.org/2000/10/swap/doc/ Commandline arguments –http://www.w3.org/2000/10/swap/doc/CwmHelphttp://www.w3.org/2000/10/swap/doc/CwmHelp Builtin functions –http://www.w3.org/2000/10/swap/doc/Built-Inhttp://www.w3.org/2000/10/swap/doc/Built-In N3Logic: A Logical Framework for the World Wide Web", Journal of Theory and Practice of Logic Programming (TPLP), Special Issue on Logic Programming and the Web –http://arxiv.org/abs/0711.1533http://arxiv.org/abs/0711.1533


Download ppt "Using Semantic Web Data: Inference Lalana Kagal Decentralized Information Group MIT CSAIL Eric Prud'hommeaux Engineer World Wide Web Consortium."

Similar presentations


Ads by Google