def has_book_info(word_objects): """ Basic information of book :param word_objects: :return: """ for r in basic_book_info_fd: keyword = r.apply(word_objects) if keyword is not None: keyword_split = re.split("( )+", keyword) keyword_db = keyword_split.pop() keyword_split.pop() keyword_douban = keyword_split.pop() break select = u"?x" sparql = None for w in word_objects: if w.pos == pos_book_or_movie: e_douban = u"?b :book_info_name '{book}'." \ u"?b {keyword} ?x.".format(book=w.token, keyword=keyword_douban) e_db = u"?m rdfs:label '{book}'@en.\n" \ u"?m dbo:author ?p.\n" \ u"?m {keyword} ?x".format(book=re.sub(r"(\w)([A-Z])", r"\1 \2", w.token), keyword=keyword_db) sparql = SPARQL_SELECT_TEM_FD.format(prefix=SPARQL_PREFIX, select=select, expression_douban=e_douban, expression_db=e_db) break return sparql
def has_movie_info(word_objects): """ The basic information about a moive某电影的基本信息 :param word_objects: :return: """ keyword = None for r in basic_movie_info_fd: keyword = r.apply(word_objects) if keyword is not None: keyword_split = re.split("( )+", keyword) keyword_db = keyword_split.pop() keyword_split.pop() keyword_douban = keyword_split.pop() break select = u"?x" sparql = None for w in word_objects: if w.pos == pos_book_or_movie: e_douban = u"?s :movie_info_name '{movie}'." \ u"?s {keyword} ?x.".format(movie=w.token, keyword=keyword_douban) e_db = u"?m rdfs:label '{movie}'@en.\n" \ u"?m dbo:starring ?p.\n" \ u"?m {keyword} ?x".format(movie=re.sub(r"(\w)([A-Z])", r"\1 \2", w.token), keyword=keyword_db) sparql = SPARQL_SELECT_TEM_FD.format(prefix=SPARQL_PREFIX, select=select, expression_douban=e_douban, expression_db=e_db) break return sparql
def has_movie_person_info(word_objects): """ someone's basic information :param word_objects: :return: """ keyword = None for r in basic_movie_person_fd: keyword = r.apply(word_objects) if keyword is not None: keyword_split = re.split("( )+", keyword) keyword_db = keyword_split.pop() keyword_split.pop() keyword_douban = keyword_split.pop() break select = u"?x" sparql = None for w in word_objects: if w.pos == pos_person: e_douban = u"?p :movie_person_name '{person}'.\n" \ u"?p {keyword} ?x.".format(person=w.token, keyword=keyword_douban) e_db = u"?p rdfs:label '{person}'@en.\n" \ u"?m dbo:starring ?p.\n" \ u"?p {keyword} ?x".format(person=re.sub(r"(\w)([A-Z])", r"\1 \2", w.token),keyword=keyword_db) sparql = SPARQL_SELECT_TEM_FD.format( prefix=SPARQL_PREFIX, select=select, expression_douban=e_douban, expression_db=e_db) break return sparql
def has_acted_in(word_objects): """ what movies does someone act in? :param word_objects: :return: """ select = u"?x" sparql = None for w in word_objects: if w.pos == pos_person: e_db = u"?p rdfs:label '{person}'@en.\n" \ u"?m dbo:starring ?p.\n" \ u"?m foaf:name ?x".format(person=re.sub(r"(\w)([A-Z])", r"\1 \2", w.token)) e_douban = u"?p :movie_person_name '{person}'.\n" \ u"?p :has_acted_in ?m.\n" \ u"?m :movie_info_name ?x".format(person=w.token) sparql = SPARQL_SELECT_TEM_FD.format( prefix=SPARQL_PREFIX, select=select, expression_douban=e_douban, expression_db=e_db) break return sparql
def has_largestcity(word_objects): """ largestcity of a country :param word_objects: :return: """ select = u"?x" sparql = None for w in word_objects: if w.pos == pos_country: e_douban = u"?c rdfs:label '{country}'@en.\n" \ u"?c dbo:largestCity ?l.\n" \ u"?l foaf:name ?x".format(country=w.token) e_db = u"?c rdfs:label '{country}'@en.\n" \ u"?c dbo:largestCity ?l.\n" \ u"?l foaf:name ?x".format(country=re.sub(r"(\w)([A-Z])", r"\1 \2", w.token)) sparql = SPARQL_SELECT_TEM_FD.format( prefix=SPARQL_PREFIX, select=select, expression_douban=e_douban, expression_db=e_db) break return sparql
def has_country_info(word_objects): """ The basic information about a country :param word_objects: :return: """ keyword = None for r in basic_country_info_fd: keyword = r.apply(word_objects) if keyword is not None: keyword_split = re.split("( )+", keyword) keyword_db = keyword_split.pop() keyword_split.pop() keyword_douban = keyword_split.pop() break select = u"?x" sparql = None for w in word_objects: if w.pos == pos_country: e_douban = u"?c rdfs:label '{country}'@en." \ u"?c {keyword} ?x.".format(country=w.token, keyword=keyword_douban) e_db = u"?c rdfs:label '{country}'@en.\n" \ u"?c {keyword} ?x".format(country=re.sub(r"(\w)([A-Z])", r"\1 \2", w.token), keyword=keyword_db) sparql = SPARQL_SELECT_TEM_FD.format( prefix=SPARQL_PREFIX, select=select, expression_douban=e_douban, expression_db=e_db) break return sparql
def has_abstract(word_objects): """ what are the abstract of a singer :param word_objects: :return: """ select = u"?x" sparql = None for w in word_objects: if w.pos == pos_singer: e_douban = u"?c rdfs:label '{singer}'@en.\n" \ u"?c dbo:abstract ?l.\n" \ u"?l foaf:name ?x".format(singer=w.token) e_db = u"?c rdfs:label '{singer}'@en.\n" \ u"?c dbo:abstract ?x.".format(singer=re.sub(r"(\w)([A-Z])", r"\1 \2", w.token)) sparql = SPARQL_SELECT_TEM_FD.format( prefix=SPARQL_PREFIX, select=select, expression_douban=e_douban, expression_db=e_db) break return sparql
def has_musicalArtist(word_objects): """ what are the musical arts of a singer """ select = u"?l" sparql = None for w in word_objects: if w.pos == pos_singer: e_douban = u"?c rdfs:label '{singer}'@en.\n" \ u"?c dbo:musicalArtist ?l.\n" \ u"?l foaf:name ?x".format(singer=w.token) e_db = u"?c rdfs:label '{singer}'@en.\n" \ u"?x dbo:musicalArtist ?c.\n" \ u"?x dbp:title ?l".format(singer=re.sub(r"(\w)([A-Z])", r"\1 \2", w.token)) sparql = SPARQL_SELECT_TEM_FD.format( prefix=SPARQL_PREFIX, select=select, expression_douban=e_douban, expression_db=e_db) break return sparql
def has_translator(word_objects): """ what are the translator of book? :param word_objects: :return: """ select = u"?x" sparql = None for w in word_objects: if w.pos == pos_book_or_movie: e_douban = u"?b :book_info_name '{book}'." \ u"?b :has_translator ?a." \ u"?a :book_person_name ?x".format(book=w.token) e_db = u"?m rdfs:label '{book}'@en.\n" \ u"?m dbo:translator ?p.\n" \ u"?p foaf:name ?x".format(book=re.sub(r"(\w)([A-Z])", r"\1 \2", w.token)) sparql = SPARQL_SELECT_TEM_FD.format(prefix=SPARQL_PREFIX, select=select, expression_douban=e_douban, expression_db=e_db) break return sparql
def has_actor(word_objects): """ What are actors in a movie某电影有哪些演员 :param word_objects: :return: """ select = u"?x" sparql = None for w in word_objects: if w.pos == pos_book_or_movie: e_douban = u"?m :movie_info_name '{movie}'." \ u"?m :has_actor ?a." \ u"?a :movie_person_name ?x".format(movie=w.token) e_db = u"?m rdfs:label '{movie}'@en.\n" \ u"?m dbo:starring ?p.\n" \ u"?p foaf:name ?x".format(movie=re.sub(r"(\w)([A-Z])", r"\1 \2", w.token)) sparql = SPARQL_SELECT_TEM_FD.format(prefix=SPARQL_PREFIX, select=select, expression_douban=e_douban, expression_db=e_db) break return sparql
def has_book_genre(word_objects): """ what is the genre of a book :param word_objects: :return: """ select = u"?x" sparql = None for w in word_objects: if w.pos == pos_book_or_movie: e_douban = u"?b :book_info_name '{book}'." \ u"?b :has_book_genre ?g."\ u"?g :book_genre_name ?x".format(book=w.token) e_db = u"?m rdfs:label '{book}'@en.\n" \ u"?m dbo:literaryGenre ?p.\n" \ u"?p foaf:name ?x".format(book=re.sub(r"(\w)([A-Z])", r"\1 \2", w.token)) sparql = SPARQL_SELECT_TEM_FD.format(prefix=SPARQL_PREFIX, select=select, expression_douban=e_douban, expression_db=e_db) break return sparql
def has_authored_in(word_objects): """ Who writes what books (e.g. Stephen King) :param word_objects: :return: """ select = u"?x" sparql = None for w in word_objects: if w.pos == pos_person: e_douban = u"?p :book_person_name '{person}'." \ u"?p :has_authored_in ?b." \ u"?b :book_info_name ?x".format(person=w.token) e_db = u"?p rdfs:label '{person}'@en.\n" \ u"?m dbo:author ?p.\n" \ u"?m foaf:name ?x".format(person=re.sub(r"(\w)([A-Z])", r"\1 \2", w.token)) sparql = SPARQL_SELECT_TEM_FD.format( prefix=SPARQL_PREFIX, select=select, expression_douban=e_douban, expression_db=e_db) break return sparql