【问题标题】:Not able to access passed list of words in get url无法访问获取 url 中传递的单词列表
【发布时间】:2017-09-26 06:06:46
【问题描述】:

如何从邮递员那里传递list 以及如何访问多个属性

@api.route('/Spacy/<input>/<texts>')
class Spacy(Resource):
    if input == pos:
        def get(self, input):
            '''
            Returns part-of speech.
            '''
            doc = nlp(texts)
            return [(word.text, word.lemma_, word.pos_) for word in doc]
    elif input == verb:
        def get(self, input):
            '''
            Returns verbs and the stemmed verb.
            '''
            doc = nlp(texts)
            return [(word.text, word.lemma_) for word in doc if word.pos_ == "VERB"]
    elif input == synonyms:
        def get(self, input):
            '''
            Returns the synonyms.
            '''
            synonyms = wordnet.synsets(input)
            lemmas = set(chain.from_iterable([word.lemma_names() for word in synonyms]))
            return jsonify([syn.replace("_"," ") for syn in list(lemmas)])

我通过/spacy?input=verb,synonyms&amp;text=flower 我应该如何接受并通过代码

我也在用 spacy

【问题讨论】:

    标签: python flask nltk flask-restful spacy


    【解决方案1】:

    您可以将查询参数更改为/spacy?input=verb&amp;input=synonyms&amp;text=flower。并使用request.args.getlist("input") 获取input 的列表值。

    【讨论】:

    • 能否举个例子,会更有帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-10-23
    • 2012-05-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多