def has_detail_information(word_objects):
        """
        某书籍的详细信息
        :param word_objects:
        :return:
        """
        select = u"?x"
        information_list = [
            BookPropertyValueSet.return_book_info_image_url_value(),
            BookPropertyValueSet.return_book_info_press_value(),
            BookPropertyValueSet.return_book_info_publish_year_value(),
            BookPropertyValueSet.return_book_info_page_num_value(),
            BookPropertyValueSet.return_book_info_price_value(),
            BookPropertyValueSet.return_book_info_content_abstract_value(),
            BookPropertyValueSet.return_book_info_catalog_value(),
            BookPropertyValueSet.return_book_info_rating_value(),
            BookPropertyValueSet.return_book_info_review_count_value()
        ]

        sparql_list = []
        for w in word_objects:
            if w.pos == pos_book_or_movie:
                for key_word in information_list:
                    e = u"?b :movie_info_name '{book}'." \
                        u"?b :{key_word} ?x".format(book=w.token, key_word=key_word)

                    sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREFIX,
                                                      select=select,
                                                      expression=e)
                    sparql_list.append(sparql)

                break
        return sparql_list
示例#2
0
    def has_detail_information(word_objects):
        """
        某电影的详细信息
        :param word_objects:
        :return:
        """
        select = u"?x"
        information_list = [
            MoviePropertyValueSet.return_movie_person_image_url_value(),
            MoviePropertyValueSet.return_movie_person_gender_value(),
            MoviePropertyValueSet.return_movie_person_constellation_value(),
            MoviePropertyValueSet.return_movie_person_birthday_value(),
            MoviePropertyValueSet.return_movie_person_birthplace_value(),
            MoviePropertyValueSet.return_movie_person_profession_value(),
            MoviePropertyValueSet.return_movie_person_other_name_value(),
            MoviePropertyValueSet.return_movie_person_introduction_value()
        ]
        sparql_list = []
        for w in word_objects:
            if w.pos == pos_person:
                for keyword in information_list:
                    e = u"?p :movie_person_name '{person}'.\n" \
                        u"?p {keyword} ?x".format(person=w.token, keyword=keyword)

                    sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREFIX,
                                                      select=select,
                                                      expression=e)
                    sparql_list.append(sparql)

                break
        return sparql_list
    def has_book_info(word_objects):
        """
        某书籍的基本信息
        :param word_objects:
        :return:
        """

        keyword = None
        for r in basic_book_info:
            keyword = r.apply(word_objects)
            if keyword is not None:
                break

        select = u"?x"
        sparql = None
        for w in word_objects:
            if w.pos == pos_book_or_movie:
                e = u"?b :book_info_name '{book}'." \
                    u"?b {keyword} ?x.".format(book=w.token, keyword=keyword)

                sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREFIX, select=select, expression=e)

                break

        return sparql
    def has_detail_information(word_objects):
        """
        某电影的详细信息
        :param word_objects:
        :return:
        """
        select = u"?x"
        information_list = [
            MoviePropertyValueSet.return_movie_info_name_value(),
            MoviePropertyValueSet.return_movie_info_other_name_value(),
            MoviePropertyValueSet.return_movie_info_country_value(),
            MoviePropertyValueSet.return_movie_info_language_value(),
            MoviePropertyValueSet.return_movie_info_pubdate_value(),
            MoviePropertyValueSet.return_movie_info_duration_value(),
            MoviePropertyValueSet.return_movie_info_rating_value(),
            MoviePropertyValueSet.return_movie_info_review_count_value(),
            MoviePropertyValueSet.return_movie_info_summary_value(),
            MoviePropertyValueSet.return_movie_info_image_url_value(),
        ]
        sparql_list = []
        for w in word_objects:
            if w.pos == pos_movie:
                for key_word in information_list:
                    e = u"?m :movie_info_name '{movie}'.\n" \
                        u"?m {key_word} ?x.".format(movie=w.token, key_word=key_word)

                    sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREFIX,
                                                      select=select,
                                                      expression=e)

                    sparql_list.append(sparql)

                break
        return sparql_list
    def has_hot_movie(word_objects):
        """
        近期热门电影
        :param word_objects:
        :return:
        """
        select = u"?x ?r ?d"
        sparql = None
        year_list = []
        for w in word_objects:
            if w.pos == 'x':
                tmp = w.token
                if HanziToNumber.is_number(tmp) == True:
                    year_list.append(tmp)
                elif HanziToNumber.is_number(tmp[:-1]) == True:
                    year_list.append(tmp[:-1])
            if w.pos == 't':
                if w.token == '近期':
                    year_list.append(2019)
            if w.pos == 'm':
                tmp = w.token
                if HanziToNumber.is_number(tmp) == True:
                    year =(int(tmp) + 1900)/10
                    year_list.append(year)
                elif tmp == '几年':
                    year_list.append(201)
                else:
                    try:
                        year = HanziToNumber.getResultForDigit(str(tmp)[0:2])
                        year_list.append((int(year) + 1900)/10)
                    except:
                        pass
        if len(year_list) !=0 :
            e = u"?m :movie_info_name ?x.\n"\
                u"?m :movie_info_rating ?r.\n" \
                u"?m :movie_info_pubdate ?d.\n"\
                u"?m :movie_info_country ?c.\n" \
                u" filter(REGEX(?d,'{year}'))\n" \
                u" filter(contains(?c,'中国大陆') || contains(?c,'香港') || contains(?c,'台湾'))\n".format(year=int(year_list[0]))

            sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREFIX,
                                              select=select,
                                              expression=e) + \
                     "orderby desc(?r)\n"
            return sparql
        return sparql
    def has_translator(word_objects):
        """
        某电影有哪些译者
        :param word_objects:
        :return:
        """
        select = u"?x"
        sparql = None
        for w in word_objects:
            if w.pos == pos_book_or_movie:
                e = u"?b :book_info_name '{book}'." \
                    u"?b :has_translator ?a." \
                    u"?a :book_person_name ?x".format(book=w.token)

                sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREFIX,
                                                  select=select,
                                                  expression=e)
                break
        return sparql
    def has_book_genre(word_objects):
        """
        某书籍的类别
        :param word_objects:
        :return:
        """
        select = u"?x"
        sparql = None
        for w in word_objects:
            if w.pos == pos_book_or_movie:
                e = u"?b :book_info_name '{book}'." \
                    u"?b :has_book_genre ?g."\
                    u"?g :book_genre_name ?x".format(book=w.token)
                sparql=SPARQL_SELECT_TEM.format(prefix=SPARQL_PREFIX,
                                                select=select,
                                                expression=e)
                break

        return sparql
    def has_movie_genre(word_objects):
        """
        某电影的类别
        :return:
        """
        select = u"?x"
        sparql = None
        for w in word_objects:
            if w.pos == pos_movie:
                e = u"?m :movie_info_name '{movie}'.\n" \
                    u"?m :has_movie_genre ?g.\n" \
                    u"?g :movie_genre_name ?x".format(movie=w.token)

                sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREFIX,
                                                  select=select,
                                                  expression=e)
                break

        return sparql
示例#9
0
    def has_directed_in(word_objects):
        """
        某人导演了哪些电影
        :param word_objects:
        :return:
        """
        select = u"?x"
        sparql = None
        for w in word_objects:
            if w.pos == pos_person:
                e = u"?p :movie_person_name '{person}'.\n" \
                    u"?p :has_directed_in ?m.\n" \
                    u"?m :movie_info_name ?x".format(person=w.token)

                sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREFIX,
                                                  select=select,
                                                  expression=e)
                break

        return sparql
    def has_translated_in(word_objects):
        """
        某人写了哪些书籍
        :param word_objects:
        :return:
        """
        select = u"?x"
        sparql = None
        for w in word_objects:
            if w.pos == pos_person:
                e = u"?p :book_person_name '{person}'." \
                    u"?p :has_translated_in ?b." \
                    u"?b :book_info_name ?x".format(person=w.token)

                sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREFIX,
                                                  select=select,
                                                  expression=e)
                break

        return sparql
    def has_director(word_objects):
        """
        某电影有哪些导演
        :param word_objects:
        :return:
        """
        select = u"?x"
        sparql = None
        for w in word_objects:
            if w.pos == pos_book_or_movie:
                e = u"?m :movie_info_name '{movie}'.\n" \
                    u"?m :has_director ?a.\n" \
                    u"?a :movie_person_name ?x".format(movie=w.token)

                sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREFIX,
                                                  select=select,
                                                  expression=e)
                break

        return sparql
    def has_book_person_info(word_objects):
        """
        某人的基本信息
        :return:
        """
        keyword = None
        for r in basic_book_person:
            keyword = r.apply(word_objects)
            if keyword is not None:
                break

        select = u"?x"
        sparql = None
        for w in word_objects:
            if w.pos == pos_person:
                e = u"?p :book_person_name '{person}'." \
                    u"?p {keyword} ?x.".format(person=w.token, keyword=keyword)
                sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREFIX,
                                                  select=select,
                                                  expression=e)
                break

        return sparql
    def has_director(word_objects):
        """
        某电影有哪些导演
        :param word_objects:
        :return:
        """
        select = u"?x (COUNT(?r) AS ?count)"
        sparql = None
        for w in word_objects:
            if w.pos == pos_movie:
                e = u"?m :movie_info_name '{movie}'.\n" \
                    u"?m :has_director ?a.\n" \
                    u"?a :has_directed_in ?r.\n"\
                    u"?a :movie_person_name ?x".format(movie=w.token)

                sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREFIX,
                                                  select=select,
                                                  expression=e) \
                         + "groupby ?x \n" \
                         + "orderby desc(?count)"
                break

        return sparql