# question-answering! # run: python qa.py what is the land area of New York? import sys import re; from rdflib import Graph, Namespace, Literal dc = Namespace("http://purl.org/dc/elements/1.1/") store = Graph(); store.parse("states.n3", None, 'n3'); m = re.search('what is the (.*) of (.*?)\??$', " ".join(sys.argv)); if m: term = m.group(1); term = term.replace(' ', ''); entityname = m.group(2); # find the predicate that ends with term predicate = None for p in store.predicates() : if (p.lower().endswith(term.lower())) : predicate = p # find the entity whose name is given entity = store.value(None, dc["title"], Literal(entityname)); if predicate == None: print "Predicate " + term + " not found." elif entity == None: print "Entity " + entityname + " not found." else : value = store.value(entity, predicate, None); print entityname + "'s " + m.group(1) + " is " + value else : print "I don't understand the question."