Commit 5a57ab5c authored by O'Reilly Media, Inc.'s avatar O'Reilly Media, Inc.
Browse files

Initial commit

parents
Loading
Loading
Loading
Loading
+6 KiB

File added.

No diff preview for this file type.

+6 KiB

File added.

No diff preview for this file type.

+1 −0
Changes for Programming-the-Semantic-Web/chapter10/city_locations.csv: 1 added line, 0 removed lines.
Original line number Diff line number Diff line
"san_francisco_ca","37.775","-122.4183""new_york_ny","40.7142","-74.0064""boulder_co","40.015","-105.27""pittsburgh_pa","40.4406","-79.9961""redmond_wa","47.6742","-122.1203""dallas_tx","32.7833","-96.8""seattle_wa","47.6064","-122.3308""washington_dc","38.69","-77.03""tempe_az","33.4147","-111.9086"
 No newline at end of file
+61 −0
Changes for Programming-the-Semantic-Web/chapter10/convert_jobs.py: 61 added lines, 0 removed lines.
Original line number Diff line number Diff line
from rdflib.Graph import ConjunctiveGraph
from rdflib import Namespace, BNode, Literal, RDF, URIRef
import csv
import pysesame

JOBS = Namespace("http://www.medev.ac.uk/interoperability/rss/1.0/modules/jobs/rss1.0jobsmodule#")
DC = Namespace("http://purl.org/dc/elements/1.1/")
JB = Namespace("http://semprog.com/schemas/jobboard#")
COMPANY = Namespace("http://purl.org/rss/1.0/modules/company/")
RDFS=Namespace('http://www.w3.org/2000/01/rdf-schema#')

jg=ConjunctiveGraph()
jg.bind('jobs',JOBS)
jg.bind('dc',DC)
jg.bind('jobboard',JB)
jg.bind('company',COMPANY)
jg.bind('rdfs',RDFS)

# Incremental counter for vacancy IDs
vid=0

for title,salary,location,company,crunchbase,ticker in csv.reader(file('joblist.csv')):
    # Create the vacancy
    vid+=1
    vacancy=JB[str(vid)]
    jg.add((vacancy,RDF.type,JOBS['Vacancy']))
    jg.add((vacancy,DC['title'],Literal(title)))
    
    location_id=location.lower().replace(' ','_').replace(',','')
    jg.add((vacancy,JB['location'],JB[location_id]))
    jg.add((JB[location_id],DC['title'],Literal(location)))
    
    # Salary range
    salaryrange=BNode()
    jg.add((vacancy,JOBS['salaryrange'],salaryrange))
    jg.add((salaryrange,JOBS['minimumsalary'],Literal(float(salary))))

    # Create the company
    cnode=JB[company.lower().replace(' ','_')]
    jg.add((vacancy,JOBS['vacancywith'],cnode))
    jg.add((cnode,RDF.type,JOBS['Organization']))
    
    # Ticker symbol
    if ticker!="":
        jg.add((cnode,COMPANY['symbol'],Literal(ticker)))
    jg.add((cnode,COMPANY['name'],Literal(company)))
    
    # Crunchbase (see also)
    if crunchbase!="":
        jg.add((cnode,RDFS['seeAlso'],
                Literal('http://api.crunchbase.com/v/1/company/%s.js' % crunchbase)))
    
# Print the serialized graph
data=jg.serialize(format='xml')
print data
#c=pysesame.connection('http://freerisk.org:8280/openrdf-sesame/')
#c.use_repository('joblistings')
#print c.postdata(data)


    
+52 −0
Changes for Programming-the-Semantic-Web/chapter10/crunchbase_data.py: 52 added lines, 0 removed lines.
Original line number Diff line number Diff line
from rdflib.Graph import ConjunctiveGraph
from rdflib import Namespace, BNode, Literal, RDF, URIRef
from pysesame import connection
import urllib
from simplejson import loads

# Connecion to Sesame
con=connection('http://freerisk.org:8280/openrdf-sesame/')
con.use_repository('joblistings')
con.addnamespace('rdfs','http://www.w3.org/2000/01/rdf-schema#')

JB = Namespace("http://semprog.com/schemas/jobboard#")
DC = Namespace("http://purl.org/dc/elements/1.1/")
FOAF = Namespace("http://xmlns.com/foaf/0.1/")

cg=ConjunctiveGraph()
cg.bind('dc',DC)
cg.bind('jobboard',JB)
cg.bind('foaf',FOAF)

# Find seeAlso URLs containing Crunchbase
res=con.query('select ?id ?url where {?id rdfs:seeAlso ?url . FILTER regex(?url, "crunchbase")}')

# Loop over the results
for row in res:
    company=URIRef(row['id']['value'])
    url=row['url']['value']
    data=urllib.urlopen(url).read()
    record=loads(data)

    # Add company locations
    for loc in record['offices']:
        if loc['city'] and loc['state_code']:
            cityid='%s_%s' % (loc['city'].lower().replace(' ','_'),loc['state_code'].lower())
            cg.add((company,JB['location'],JB[cityid]))

    # Add URL
    cg.add((company,FOAF['homepage'],Literal(record['homepage_url'])))

    # Add funding rounds
    for fr in record['funding_rounds']:
        round=BNode()
        cg.add((company,JB['funding_round'],round))
        cg.add((round,JB['amount'],Literal(fr['raised_amount'])))
        cg.add((round,DC['date'], Literal(str(fr['funded_year']))))


data=cg.serialize(format='xml')
print data
#c=pysesame.connection('http://freerisk.org:8280/openrdf-sesame/')
#c.use_repository('joblistings')
#print c.postdata(data)
Loading