Mosa Abbas
Mosa Abbas

Reputation: 149

how to search for jobs using semantic search and ontology using python?

i'm building a simple online semantic search engine to find jobs and i found a simple program that reads a local owl file but i want it to be online to fined jobs and employers using the semantic web and linked data

from owlready2 import *


class SparqlQueries:
def __init__(self):
    my_world = World()
    my_world.get_ontology("file://ExampleOntolohy.owl").load() #path to the owl file is given here
    sync_reasoner(my_world)  #reasoner is started and synchronized here
    self.graph = my_world.as_rdflib_graph()

def search(self):
    #Search query is given here
    #Base URL of your ontology has to be given here
    query = "base <http://www.semanticweb.org/ExampleOntology> " \
            "SELECT ?s ?p ?o " \
            "WHERE { " \
            "?s ?p ?o . " \
            "}"

    #query is being run
    resultsList = self.graph.query(query)

    #creating json object
    response = []
    for item in resultsList:
        s = str(item['s'].toPython())
        s = re.sub(r'.*#',"",s)

        p = str(item['p'].toPython())
        p = re.sub(r'.*#', "", p)

        o = str(item['o'].toPython())
        o = re.sub(r'.*#', "", o)
        response.append({'s' : s, 'p' : p, "o" : o})

    print(response) #just to show the output
    return response


runQuery = SparqlQueries()
runQuery.search()

I've tried to use RDFlib like what it was mentioned in the documentation

import rdflib
g=rdflib.Graph()
g.load('http://dbpedia.org/resource/Semantic_Web')

for s,p,o in g:
    print s,p,o

what i should do to get data and links about jobs ? or about employers or companies ?

and how should i write the owl file ?

Upvotes: 0

Views: 516

Answers (1)

Paul Brown
Paul Brown

Reputation: 2403

schema.org have a JobPosting specification. If you're lucky you'll find some websites using it and using it well. Depending on how they do (in the linked docs), you'll be able to scrape it into your own graph. That'll save authoring an ontology at least.

I just looked at just one job website: Monster.com, they're kind enough to put Schema lists in JSON-LD on their collection pages, line 1187 in the linked source, as well as Schema JobPostings on the linked pages, line 261 in the linked source.

If you have both rdflib and rdflib-jsonld pip installed, then it's a simple as:

from rdflib import Graph
g = Graph()
g.parse("https://job-openings.monster.com/software-engineer-principal-software-engineer-northridge-ca-us-northrop-grumman/0d2caa9e-3b3c-46fa-94d1-cddc75d9ae27")

# Demo
print(len(g))
for s, p, o in g:
    print(s, p, o)

Upvotes: 2

Related Questions