Пример #1
0
    def has_basic_person_info_question(word_objects):
        """
        某演员的基本信息是什么
        :param word_objects:
        :return:
        """

        keyword = None
        for r in person_basic_keyword_rules:
            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"?s :personName '{person}'." \
                    u"?s {keyword} ?x.".format(person=w.token, keyword=keyword)

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

                break

        return sparql
Пример #2
0
    def has_cooperation_question(word_objects):
        """
        演员A和演员B有哪些合作的电影
        :param word_objects:
        :return:
        """
        select = u"?x"

        person1 = None
        person2 = None

        for w in word_objects:
            if w.pos == pos_person:
                if person1 is None:
                    person1 = w.token
                else:
                    person2 = w.token
        if person1 is not None and person2 is not None:
            e = u"?p1 :personName '{person1}'." \
                u"?p2 :personName '{person2}'." \
                u"?p1 :hasActedIn ?m." \
                u"?p2 :hasActedIn ?m." \
                u"?m :movieTitle ?x".format(person1=person1, person2=person2)

            return SPARQL_SELECT_TEM.format(prefix=SPARQL_PREXIX,
                                            select=select,
                                            expression=e)
        else:
            return None
Пример #3
0
    def has_basic_movie_info_question(word_objects):
        """
        某电影的基本信息是什么
        :param word_objects:
        :return:
        """

        keyword = None
        for r in movie_basic_keyword_rules:
            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_movie:
                e = u"?s :movieTitle '{movie}'." \
                    u"?s {keyword} ?x.".format(movie=w.token, keyword=keyword)

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

                break

        return sparql
Пример #4
0
    def has_specific_type_movie_question(word_objects):
        """
        某演员演了什么类型(指定类型,喜剧、恐怖等)的电影
        :param word_objects:
        :return:
        """
        select = u"?x"

        keyword = None
        for r in genre_keyword_rules:
            keyword = r.apply(word_objects)

            if keyword is not None:
                break

        sparql = None
        for w in word_objects:
            if w.pos == pos_person:
                e = u"?s :personName '{person}'." \
                    u"?s :hasActedIn ?m." \
                    u"?m :hasGenre ?g." \
                    u"?g :genreName '{keyword}'." \
                    u"?m :movieTitle ?x".format(person=w.token, keyword=keyword)

                sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREXIX,
                                                  select=select,
                                                  expression=e)
                break
        return sparql
Пример #5
0
    def show_detail_question(word_objects):
        """
        问题十:某产品某属性具体值是什么
        :param word_objects:
        :return:
        """
        select = u"?cid ?brand ?model"

        brand = None
        for w in word_objects:
            if w.pos == pos_brand:
                brand = w.token
                break

        model = None
        for w in word_objects:
            if w.pos == pos_model:
                model = w.token
                break

        if not model:
            return None, 0
        else:
            if brand:
                brand = wordTagging.after_process(brand)
            model = wordTagging.after_process(model)

        sparql = None
        suffix = ""
        if not brand:
            e = u"?cidid :catalogid_cid ?cid." \
                u"?modelid :model_to_catalog ?cidid." \
                u"?modelid :model_brand ?brand." \
                u"?modelid :model_model '{model}'."\
                u"?modelid :model_model ?model.".format(model=model)
        else:
            e = u"?cidid :catalogid_cid ?cid." \
                u"?modelid :model_to_catalog ?cidid." \
                u"?modelid :model_brand '{brand}'." \
                u"?modelid :model_brand ?brand." \
                u"?modelid :model_model '{model}'." \
                u"?modelid :model_model ?model.".format(brand=brand,
                                                        model=model)

        sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREXIX,
                                          select=select,
                                          expression=e,
                                          suffix=suffix)
        return sparql, len(select.split())
Пример #6
0
    def product_has_performance_score_question(word_objects):
        """
        某品牌-型号某项属性的得分
        :param word_objects:
        :return:
        """
        select = u"?brand ?model ?attr ?score"

        brand = None
        for w in word_objects:
            if w.pos == pos_brand:
                brand = w.token
                break

        model = None
        for w in word_objects:
            if w.pos == pos_model:
                model = w.token
                break

        if not brand or not model:
            return None, 0
        else:
            brand = wordTagging.after_process(brand)
            model = wordTagging.after_process(model)

        sparql = None
        suffix = ""
        for w in word_objects:
            if w.pos == pos_attribute:
                e = u"?s :model_to_function ?o." \
                    u"?s :model_brand '{brand}'." \
                    u"?s :model_brand ?brand." \
                    u"?s :model_model '{model}'." \
                    u"?s :model_model ?model." \
                    u"?o :function_name '{function}'." \
                    u"?o :function_name ?attr." \
                    u"?x :model_to_function_id ?s." \
                    u"?x :model_to_function_funcid ?o." \
                    u"?x :model_to_function_score ?score.".format(function=w.token,
                                                                  brand=brand,
                                                                  model=model)

                sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREXIX,
                                                  select=select,
                                                  expression=e,
                                                  suffix=suffix)
                break
        return sparql, len(select.split())
Пример #7
0
    def has_color_question(word_objects):
        """
        问题九:某产品某属性具体值是什么
        :param word_objects:
        :return:
        """
        select = u"?attr"

        brand = None
        for w in word_objects:
            if w.pos == pos_brand:
                brand = w.token
                break

        model = None
        for w in word_objects:
            if w.pos == pos_model:
                model = w.token
                break

        if not model:
            return None, 0
        else:
            if brand:
                brand = wordTagging.after_process(brand)
            model = wordTagging.after_process(model)

        sparql = None
        suffix = ""
        if not brand:
            e = u"?modelid :model_model '{model}'." \
                u"?modelid :hasColor ?attrid." \
                u"?attrid :function_name ?attr".format(model=model)
        else:
            e = "?modelid :model_brand '{brand}'." \
                u"?modelid :model_model '{model}'." \
                u"?modelid :hasColor ?attrid."\
                u"?attrid :function_name ?attr".format(brand=brand,
                                                       model=model)

        sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREXIX,
                                          select=select,
                                          expression=e,
                                          suffix=suffix)
        return sparql, len(select.split())
Пример #8
0
    def has_movie_question(word_objects):
        """
        某演员演了什么电影
        :param word_objects:
        :return:
        """
        select = u"?x"

        sparql = None
        for w in word_objects:
            if w.pos == pos_person:
                e = u"?s :personName '{person}'." \
                    u"?s :hasActedIn ?m." \
                    u"?m :movieTitle ?x".format(person=w.token)

                sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREXIX,
                                                  select=select,
                                                  expression=e)
                break
        return sparql
Пример #9
0
    def has_actor_question(word_objects):
        """
        哪些演员参演了某电影
        :param word_objects:
        :return:
        """
        select = u"?x"

        sparql = None
        for w in word_objects:
            if w.pos == pos_movie:
                e = u"?m :movieTitle '{movie}'." \
                    u"?m :hasActor ?a." \
                    u"?a :personName ?x".format(movie=w.token)

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

        return sparql
Пример #10
0
    def product_whether_nice_question(word_objects):
        """
        问题五:询问某品类中某个产品的某项属性好不好
        :param word_objects:
        :return:
        """
        select = "?score ?highest ?rank ?total"

        sparql = None
        suffix = ""

        brand = None
        for w in word_objects:
            if w.pos == pos_brand:
                brand = w.token
                break

        model = None
        for w in word_objects:
            if w.pos == pos_model:
                model = w.token
                break

        if not brand or not model:
            return None, 0
        else:
            brand = wordTagging.after_process(brand)
            model = wordTagging.after_process(model)

        e = "{" + AuxiliaryQuestionSet.product_has_performance_score_question(word_objects)[0][296:] + "}" + \
            "{" + AuxiliaryQuestionSet.product_highest_performance_question(word_objects)[0][296:].replace(
            "?brand ?model ", "") + "}" + \
            "{" + AuxiliaryQuestionSet.product_has_performance_rank_question(word_objects)[0][296:] + "}" + \
            "{" + AuxiliaryQuestionSet.product_has_performance_total_question(word_objects)[0][296:] + "}"

        sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREXIX,
                                          select=select,
                                          expression=e,
                                          suffix=suffix)
        return sparql, len(select.split())
Пример #11
0
    def product_highest_performance_question(word_objects):
        """
        某品类某属性的最高得分
        :param word_objects:
        :return:
        """
        select = u"?brand ?model ?attr ?highest"

        cidname = None
        for w in word_objects:
            if w.pos == pos_cidname:
                cidname = w.token
                break

        if not cidname:
            return None, 0

        sparql = None
        suffix = ORDER_DESC_TEM.format(key="?highest") + LIMIT_TEM.format(
            limit=1)
        for w in word_objects:
            if w.pos == pos_attribute:
                e = u"?cid :catalogid_cidname '{cidname}'." \
                    u"?s :model_to_catalog ?cid." \
                    u"?s :model_to_function ?o." \
                    u"?s :model_brand ?brand." \
                    u"?s :model_model ?model." \
                    u"?o :function_name '{function}'." \
                    u"?o :function_name ?attr." \
                    u"?x :model_to_function_score ?highest." \
                    u"?x :model_to_function_id ?s." \
                    u"?x :model_to_function_funcid ?o.".format(cidname=cidname,
                                                               function=w.token)

                sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREXIX,
                                                  select=select,
                                                  expression=e,
                                                  suffix=suffix)
                break
        return sparql, len(select.split())
Пример #12
0
    def has_high_performance_question(word_objects):
        """
        问题一:询问某项属性竞争力高的产品有哪些
        :param word_objects:
        :return:
        """
        select = u"?brand ?model"

        cidname = None
        for w in word_objects:
            if w.pos == pos_cidname:
                cidname = w.token
                break

        if cidname is None:
            return None, 0

        sparql = None
        suffix = ORDER_DESC_TEM.format(key="?score") + LIMIT_TEM.format(
            limit=10)
        for w in word_objects:
            if w.pos == pos_attribute:
                e = u"?cid :catalogid_cidname '{cidname}'." \
                    u"?modelid :model_to_catalog ?cid." \
                    u"?modelid :model_brand ?brand." \
                    u"?modelid :model_model ?model." \
                    u"?modelid :model_to_function ?attrid." \
                    u"?attrid :function_name '{attr}'." \
                    u"?record :model_to_function_id ?modelid." \
                    u"?record :model_to_function_funcid ?attrid." \
                    u"?record :model_to_function_score ?score." .format(cidname=cidname,
                                                                         attr=w.token)

                sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREXIX,
                                                  select=select,
                                                  expression=e,
                                                  suffix=suffix)
                break
        return sparql, len(select.split())
Пример #13
0
    def has_compare_question(word_objects):
        """
        某演员参演的评分高于X的电影有哪些?
        :param word_objects:
        :return:
        """
        select = u"?x"

        person = None
        number = None
        keyword = None

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

        for w in word_objects:
            if w.pos == pos_person:
                person = w.token

            if w.pos == pos_number:
                number = w.token

        if person is not None and number is not None:

            e = u"?p :personName '{person}'." \
                u"?p :hasActedIn ?m." \
                u"?m :movieTitle ?x." \
                u"?m :movieRating ?r." \
                u"filter(?r {mark} {number})".format(person=person, number=number,
                                                     mark=keyword)

            return SPARQL_SELECT_TEM.format(prefix=SPARQL_PREXIX,
                                            select=select,
                                            expression=e)
        else:
            return None
Пример #14
0
    def care_product_aspect_question(word_objects):
        """
        问题七:在某个品类中用户一般关心什么属性/功能
        :param word_objects:
        :return:
        """
        select = u"?attr"

        sparql = None
        suffix = ""
        for w in word_objects:
            if w.pos == pos_cidname:
                e = u"?cid :catalogid_cidname '{cidname}'." \
                    u"?modelid :model_to_catalog ?cid." \
                    u"?modelid :model_to_function ?attrid." \
                    u"?attrid :function_name ?attr.".format(cidname=w.token)

                sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREXIX,
                                                  select=select,
                                                  expression=e,
                                                  suffix=suffix)
                break
        return sparql, len(select.split())
Пример #15
0
    def top_biz_with_attr_question(word_objects):
        """
        问题八:列举某项指标排名前几的某品类产品
        :param word_objects:
        :return:
        """
        select = u"?brand ?model"

        cidname = None
        for w in word_objects:
            if w.pos == pos_cidname:
                cidname = w.token
                break

        if cidname is None:
            return None, 0

        sparql = None
        suffix = ORDER_DESC_TEM.format(key="?biz30day") + LIMIT_TEM.format(
            limit=5)
        for w in word_objects:
            if w.pos == pos_attribute:
                e = u"?cid :catalogid_cidname '{cidname}'." \
                    u"?modelid :model_to_catalog ?cid." \
                    u"?modelid :model_brand ?brand." \
                    u"?modelid :model_model ?model." \
                    u"?modelid :model_model ?biz30day." \
                    u"?modelid :model_to_function ?attrid." \
                    u"?attrid :function_name '{attr}'.".format(cidname=cidname,
                                                               attr=w.token)

                sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREXIX,
                                                  select=select,
                                                  expression=e,
                                                  suffix=suffix)
                break
        return sparql, len(select.split())
Пример #16
0
    def catalog_has_performance_question(word_objects):
        """
        问题二:询问有某项功能的品类有哪些
        :param
        word_objects:
        :return:
        """
        select = "?cidname"

        sparql = None
        suffix = ""
        for w in word_objects:
            if w.pos == pos_attribute:
                e = u"?cid :catalogid_cidname ?cidname." \
                    u"?modelid :model_to_catalog ?cid." \
                    u"?modelid :model_to_function ?attrid." \
                    u"?attrid :function_name '{attr}'.".format(attr=w.token)

                sparql = SPARQL_SELECT_TEM.format(prefix=SPARQL_PREXIX,
                                                  select=select,
                                                  expression=e,
                                                  suffix=suffix)
                break
        return sparql, len(select.split())