3. how do you store your data?
[ ] data... what data?!
[ ] raw files (csv, json, xml)
[ ] database (eg. Relational Data Base)
[ ] graphs (eg. Resource Description Framework)
[ ] other...
4. how do you search for...?
Apartments near English-Portuguese bilingual
childcare in Rio de Janeiro state.
ERP service providers with offices in São Paulo
and New York.
Researchers working on artificial intelligence in
Southeast of Brazil.
GNU GPL software for image processing
developed from 2009 to 2010 authored also by
Brazilian developers
5. how do you search for...?
Apartments near English-Portuguese bilingual
childcare in Rio de Janeiro state.
ERP service providers with offices in São Paulo
and New York.
Researchers working on artificial intelligence in
Southeast of Brazil.
GNU GPL software for image processing
developed from 2009 to 2010 authored also by
Brazilian developers
6. how do you search for...?
Apartments near English-Portuguese bilingual
childcare in Rio de Janeiro state.
ERP service providers with offices in São Paulo
and New York.
Researchers working on artificial intelligence in
Southeast of Brazil.
GNU GPL software for image processing
developed from 2009 to 2010 authored also by
Brazilian developers
7. how do you search for...?
Apartments near English-Portuguese bilingual
childcare in Rio de Janeiro state.
ERP service providers with offices in São Paulo
and New York.
Researchers working on artificial intelligence in
Southeast of Brazil.
GNU GPL software for image processing
developed from 2009 to 2010 authored also by
Brazilian developers
35. some options
#1: create a solution
from scratch
#2: study existing
solutions and then
[ ] contribute to them
[ ] develop on top of
them
[ ] goto #1
46. SPARQLWrapper
problem: list all predicates of a class
# List all predicates of dbonto:Band
query = """
SELECT distinct ?subject
FROM <http://dbpedia.org>
{
?subject rdfs:domain ?object .
<http://dbpedia.org/ontology/Band> rdfs:subClassOf ?object
OPTION (TRANSITIVE, t_distinct, t_step('step_no') as ?n, t_min
(0) ).
}""" http://live.dbpedia.org/sparql
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setQuery(query)
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
for result in results["results"]["bindings"]:
print(result["subject"]["value"])
47. SPARQLWrapper
abstract endpoint returns dict
# List all predicates of dbonto:Band
query = """
SELECT distinct ?subject
FROM <http://dbpedia.org>
{
?subject rdfs:domain ?object .
<http://dbpedia.org/ontology/Band> rdfs:subClassOf ?object
OPTION (TRANSITIVE, t_distinct, t_step('step_no') as ?n, t_min
(0) ).
}""" http://live.dbpedia.org/sparql
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setQuery(query)
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
for result in results["results"]["bindings"]:
print(result["subject"]["value"])
50. SPARQLWrapper
problem: list all subjects given ?p ?o
from SPARQLWrapper import SPARQLWrapper, JSON
# List all instances (eg. bands) with genre Metal
query = """
PREFIX db: <http://dbpedia.org/resource/>
PREFIX dbonto: <http://dbpedia.org/ontology/>
SELECT DISTINCT ?who
FROM <http://dbpedia.org>
WHERE {
?who dbonto:genre db:Metal .
}
"""
sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setQuery(query)
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
for result in results["results"]["bindings"]:
print(result["who"]["value"])
51. RdfLib
problem: list all subjects given ?p ?o
import rdflib
import rdfextras.store.SPARQL
# SPARQL endpoint setup
endpoint = "http://dbpedia.org/sparql"
store = rdfextras.store.SPARQL.SPARQLStore(endpoint)
graph = rdflib.Graph(store)
# Definitions
genre = rdflib.URIRef("http://dbpedia.org/ontology/genre")
metal = rdflib.URIRef("http://dbpedia.org/resource/Metal")
# Query
for label in graph.subjects(genre, metal):
print label
52. RdfLib
abstract endpoint returns dict namespace
import rdflib
import rdfextras.store.SPARQL
# SPARQL endpoint setup
endpoint = "http://dbpedia.org/sparql"
store = rdfextras.store.SPARQL.SPARQLStore(endpoint)
graph = rdflib.Graph(store)
# Namespaces to clear up definitions
DBONTO = rdflib.Namespace("http://dbpedia.org/ontology/")
DB = rdflib.Namespace("http://dbpedia.org/resource/")
# Query
for label in graph.subjects(DBONTO.genre, DB.Metal):
print label
53. RdfLib
abstract endpoint returns dict namespace
import rdflib
import rdfextras.store.SPARQL
# SPARQL endpoint setup
endpoint = "http://dbpedia.org/sparql"
store = rdfextras.store.SPARQL.SPARQLStore(endpoint)
graph = rdflib.Graph(store)
# Namespaces to clear up definitions
DBONTO = rdflib.Namespace("http://dbpedia.org/ontology/")
DB = rdflib.Namespace("http://dbpedia.org/resource/")
# Query
for label in graph.subjects(DBONTO.genre, DB.Metal):
print label
subjects
predicates
objects
subject_predicates
subject_objects
predicates_objects
54. RdfLib
abstract endpoint returns dict namespace
import rdflib
import rdfextras.store.SPARQL
# SPARQL endpoint setup
endpoint = "http://dbpedia.org/sparql"
store = rdfextras.store.SPARQL.SPARQLStore(endpoint)
graph = rdflib.Graph(store)
# Namespaces to clear up definitions
DBONTO = rdflib.Namespace("http://dbpedia.org/ontology/")
DB = rdflib.Namespace("http://dbpedia.org/resource/")
# Using triples
for musician, _, _ in graph.triples((None, DBONTO.genre, DB.Metal)):
print musician
55. RdfLib
abstract endpoint returns dict namespace query by triples
import rdflib
import rdfextras.store.SPARQL
# SPARQL endpoint setup
endpoint = "http://dbpedia.org/sparql"
store = rdfextras.store.SPARQL.SPARQLStore(endpoint)
graph = rdflib.Graph(store)
# Namespaces to clear up definitions
DBONTO = rdflib.Namespace("http://dbpedia.org/ontology/")
DB = rdflib.Namespace("http://dbpedia.org/resource/")
# Query
for label in graph.subjects(DBONTO.genre, DB.Metal):
print label
63. SuRF
problem: list all subjects given ?p ?o
from surf import Store, Session, ns, query
store = Store(reader='sparql_protocol',
endpoint='http://dbpedia.org/sparql')
session = Session(store, {})
ns.register(db='http://dbpedia.org/resource/')
ns.register(dbonto='http://dbpedia.org/ontology/')
query_surf = query.select("?who").distinct()
query_surf.where(("?who", ns.DBONTO.genre, ns.DB.Metal))
metal_bands = session.default_store.execute(query_surf)
for band in metal_bands:
print band
composed
ORM
queries
70. RDFAlchemy
problem: list all subjects given ?p ?o
from rdfalchemy.sparql import SPARQLGraph
from rdflib import Namespace
endpoint = "http://dbpedia.org/sparql"
graph = SPARQLGraph(endpoint)
DB = Namespace("http://dbpedia.org/resource/")
DBONTO = Namespace("http://dbpedia.org/ontology/")
metal_bands = graph.subjects(predicate=DBONTO.genre,
object=DB.Metal)
for band in metal_bands:
print band
71. RDFAlchemy
abstract endpoint returns dict namespace query by triples add / remove
from rdfalchemy.sparql import SPARQLGraph
from rdfalchemy import rdfSubject, rdfSingle
from rdflib import Namespace
DB = Namespace('http://dbpedia.org/resource/')
DBONTO = Namespace("http://dbpedia.org/ontology/")
RDFS = Namespace('http://www.w3.org/2000/01/rdf-schema#')
endpoint = "http://live.dbpedia.org/sparql"
graph = SPARQLGraph(endpoint)
rdfSubject.db = graph
class MusicalArtist(rdfSubject):
rdfs_label = rdfSingle(RDFS.label, 'label')
genre = rdfSingle(DBONTO.genre, 'genre')
metal_artists = MusicalArtist.filter_by(genre=DB.Metal)
for band in metal_artists:
print band
ORM django-like
80. study existing solutions, and now?
[ ] contribute to them
[ ] develop on top of them
[ ] create a solution from scratch
[ ] other, _________________
81. grab your post-it, it's review time!
=) =( comments
shows no my
SuRF query models favorite
not my
nice
models lazy choice
RDFAlchemy API
name low
RDFlib space layer
django just
semantic-django like started
(...)