460 likes | 576 Views
Semantic Web Bootcamp. Dominic DiFranzo PhD Student/Research Assistant Rensselaer Polytechnic Institute Tetherless World Constellation. http://tw.rpi.edu/portal/Mashathon. Interwebs?. Internet – graph of computers connected to one another
E N D
Semantic Web Bootcamp Dominic DiFranzo PhD Student/Research Assistant Rensselaer Polytechnic Institute Tetherless World Constellation
Interwebs? Internet – graph of computers connected to one another Web – graph of documents hyper-linked to one another Semantic web – graph of concepts/ideas/data linked together by named relations.
122.121.53.13 128.21.52.3 138.41.32.13 122.11.32.43 125.71.26.73
122.121.53.13 128.21.52.3 138.41.32.13 122.11.32.43 125.71.26.73
122.121.53.13 Hat.com/hog.html 128.21.52.3 138.41.32.13 Example.com Dig.net/log.html 122.11.32.43 125.71.26.73 Cat.com/new.html dog.com/dog.html
http://difranzo.com/index http://rpi.edu/~hendler
http://difranzo.com/index http://rpi.edu/~hendler http://example.com/isAdvisedBy
Hat.com/hog.html Example.com Dig.net/log.html Cat.com/new.html dog.com/dog.html
RDF Triple: Subject Predicate Object Use URI for universal naming New York has the postal abbreviation NY <urn:x-states:New%20York> <http://purl.org/dc/terms/alternative> "NY" .
urn:x-states:New%20York “NY” http://purl.org/dc/terms/alternative
serialize in many ways <rdf:RDFxmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:dcterms="http://purl.org/dc/terms/"> <rdf:Description rdf:about="urn:x-states:New%20York"> <dcterms:alternative>NY</dcterms:alternative> </rdf:Description> </rdf:RDF>
Linking I found a new dataset and it has the following triple <http://dbpedia.org/page/New_York> <http://dbpedia.org/ontology/Place/otherName> “The Empire State” .
http://dbpedia.org/page/New_York “The Empire State” http://dbpedia.org/ontology/Place/otherName
owl:sameAS <urn:x-states:New%20York> <http://www.w3.org/2002/07/owl#sameAs> <http://dbpedia.org/page/New_York> .
urn:x-states:New%20York http://dbpedia.org/page/New_York http://www.w3.org/2002/07/owl#sameAs “NY” “The Empire State”
Linked Data • decentralized - sources may be spread out and referenced across the Web • modular - linked without advance planning or coordination • scalable - once store in place, it’s easy to extend • advantages hold even when definitions and structure of the data changes over time.
Other Sem Web Tech • Resource Description Framework Schema (RDFS) • Defining the vocabularies intended to be used in RDF • class, property, type, subClassOf, range, and domain • Allows for reasoning over data • Web Ontology Language (OWL) • more expressive ontologies and more complex reasoning of them
Sparql SPARQL is a query language for the Semantic Web.
Sparql SELECT ?node ?title WHERE{ ?node <http://purl.org/dc/elements/1.1/title> ?title . } LIMIT 1
?node ?title http://purl.org/dc/elements/1.1/title
Long! SELECT ?node ?name WHERE{ ?node <http://xmlns.com/foaf/0.1/givenname> ?name . ?node <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://xmlns.com/foaf/0.1/Person> . } LIMIT 10
?node ?title http://purl.org/dc/elements/1.1/title foaf:Person http://www.w3.org/1999/02/22-rdf-syntax-ns#type
Prefix PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?node ?name WHERE{ ?node foaf:givenname ?name . ?node rdf:typefoaf:Person . } LIMIT 10
Shortcuts PREFIX foaf: <http://xmlns.com/foaf/0.1/> PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> SELECT ?node ?name WHERE{ ?node foaf:givenname ?name ; rdf:typefoaf:Person . } LIMIT 10
Named Graph PREFIX dc: <http://purl.org/dc/elements/1.1/> SELECT ?graph ?node ?title WHERE{ GRAPH ?graph{ ?node dc:title ?title . } } LIMIT 3
Named Graph PREFIX dc: <http://purl.org/dc/elements/1.1/> SELECT ?node8 ?desc8 ?node401 ?desc401 WHERE{ GRAPH <http://data-gov.tw.rpi.edu/vocab/Dataset_401>{ ?node401 dc:description ?desc401 . } GRAPH <http://data-gov.tw.rpi.edu/vocab/Dataset_8>{ ?node8 dc:description ?desc8 . } } LIMIT 3
Union PREFIX dc: <http://purl.org/dc/elements/1.1/> SELECT ?node8 ?desc8 ?node401 ?desc401 WHERE{ { GRAPH <http://data-gov.tw.rpi.edu/vocab/Dataset_401>{ ?node401 dc:description ?desc401 . } }UNION{ GRAPH <http://data-gov.tw.rpi.edu/vocab/Dataset_8>{ ?node8 dc:description ?desc8 . } } } LIMIT 3
Optional PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?node ?name ?givenname WHERE{ ?node foaf:name ?name . OPTIONAL{ ?node foaf:givenname ?givenname . } }
Filter PREFIX foaf: <http://xmlns.com/foaf/0.1/> SELECT ?node ?name ?givenname WHERE{ ?node foaf:name ?name . ?node foaf:givenname ?givenname . FILTER regex(?name, "Biden") . }
SPARQLProxy • This is a web service that allows you to query any SPARQL endpoint, and get back the results in any format you want. • A RESTful way to query any endpoint in any environment.
SPARQLProxy http://logd.tw.rpi.edu/sparql? Paramiters: query: [required] encoded String of SPARQL query query-uri :[required] URI of SPARQL query (use as an alternative to "query" parameter. These two parameters are mutul-exclusive)
SPARQLProxy service-uri: [required] URI of SPARQL Endpoint – default is the LOGD endpoint output: output format. ''xml'' - SPARQL/XML (default) : ''exhibit'' - JSON for MIT Exhibit : ''gvds'' - JSON for Google Visualization : ''csv'' - CSV : ''html'' - HTML table : “sparql” - SPARQL JSON
Example • http://logd.tw.rpi.edu/sparql.php?query-option=text&query=PREFIX+conversion%3A+%3Chttp%3A%2F%2Fpurl.org%2Ftwc%2Fvocab%2Fconversion%2F%3E%0D%0ASELECT+%3Fg+sum%28+%3Ftriples+%29+as+%3Festimated_triples%0D%0AWHERE+{%0D%0A++GRAPH+%3Fg++{%0D%0A+++%3Fg+void%3Asubset+%3Fsubdataset+.%0D%0A+++%3Fsubdataset+conversion%3Anum_triples+%3Ftriples+.%0D%0A++}%0D%0A}+%0D%0AGROUP+BY+%3Fg%0D%0A&service-uri=&output=html&callback=&tqx=&tp=
Example // compose query $sparqlproxy_uri = "http://logd.tw.rpi.edu/ws/sparqlproxy.php" $params = array(); $params["query-uri"] = "http://logd.tw.rpi.edu/demo/retrieving-sparql-results/datagov-list-loaded-dataset.sparql"; $params["service-uri"] = "http://services.data.gov/sparql"; $params["output"] = "gvds"; $query= $sparqlproxy_uri."?". http_build_query($params,,'&') ; //specific for Drupal //show query result echo file_get_contents($query);