当前位置: 首页>>代码示例>>Python>>正文


Python AlchemyAPI.taxonomy方法代码示例

本文整理汇总了Python中alchemyapi.AlchemyAPI.taxonomy方法的典型用法代码示例。如果您正苦于以下问题:Python AlchemyAPI.taxonomy方法的具体用法?Python AlchemyAPI.taxonomy怎么用?Python AlchemyAPI.taxonomy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在alchemyapi.AlchemyAPI的用法示例。


在下文中一共展示了AlchemyAPI.taxonomy方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ExtractTaxonomy

# 需要导入模块: from alchemyapi import AlchemyAPI [as 别名]
# 或者: from alchemyapi.AlchemyAPI import taxonomy [as 别名]
def ExtractTaxonomy(text):
    alchemyapi = AlchemyAPI()

    response = alchemyapi.taxonomy('text', text)
    results = []

    if response['status'] == 'OK':
        for category in response['taxonomy']:
            results.append(category['label'] + ' : ' + category['score'])
    else:
        print('Error in taxonomy call: ', response['statusInfo'])

    return results
开发者ID:zhewang,项目名称:salesprediction,代码行数:15,代码来源:pipeline.py

示例2: __init__

# 需要导入模块: from alchemyapi import AlchemyAPI [as 别名]
# 或者: from alchemyapi.AlchemyAPI import taxonomy [as 别名]
class NLP:
    def __init__(self):
        self.alchemyapi = AlchemyAPI()

    def get_categories(self, text):
        response = self.alchemyapi.taxonomy('text', text)

        if response['status'] == 'OK' and len(response['taxonomy']) > 0:
            taxonomy = response['taxonomy'][0]
            tokens = taxonomy['label'].split('/')
            return tokens[1]

    def get_keywords(self, text):
        response = self.alchemyapi.keywords('text', text)

        if response['status'] == 'OK' and len(response['keywords']) > 0:
            return [x['text'] for x in response['keywords']]
开发者ID:jhirniak,项目名称:pinkunicorns,代码行数:19,代码来源:nlp.py

示例3: entity_topic_extraction

# 需要导入模块: from alchemyapi import AlchemyAPI [as 别名]
# 或者: from alchemyapi.AlchemyAPI import taxonomy [as 别名]
    def entity_topic_extraction(self, myText):

        alchemyApi = AlchemyAPI()

        # put all entities in a list
        entity_list = []
        response = alchemyApi.entities('text', myText, {'sentiment': 1})
        if response['status'] == 'OK':
            for entity in response['entities']:
                #entity_list.append((entity['text'].encode('utf-8'),entity['type']))
                entity_list.append((entity['text'].encode('utf-8'), entity['type'].encode('utf-8')))


        # put all taxonomy in a list
        response = alchemyApi.taxonomy('text', myText)
        # put all taxonomy in a list
        taxonomy_list = []
        if response['status'] == 'OK':
            for category in response['taxonomy']:
                taxonomy_list.append(category['label'].encode('utf-8'))

        return entity_list, taxonomy_list
开发者ID:sunshengjing,项目名称:user_similarity,代码行数:24,代码来源:PreProcess.py

示例4: getDocCount

# 需要导入模块: from alchemyapi import AlchemyAPI [as 别名]
# 或者: from alchemyapi.AlchemyAPI import taxonomy [as 别名]
    return k


url = "http://quora-api.herokuapp.com/users/" + sys.argv[1] + "/activity"
data = requests.get(url).json()
data = data["activity"]
payload = {}
# count=0
# getDocCount()
for activities in data:
    title = activities["title"]
    summary = activities["summary"]
    print title
    document["title"] = title
    document["summary"] = summary
    labels = al.taxonomy("text", title)
    entities = al.entities("html", summary)
    keywords = al.keywords("html", summary)
    sentiment = al.sentiment("html", summary)
    # print labels['taxonomy']
    # count+=1
    payload["entities"] = {}
    payload["keywords"] = []
    payload["sentiment"] = {}
    docNode = createDocNode(document)
    try:
        print "Yo"
        labels = labels["taxonomy"][0]["label"]
        print "Yo1"
        print labels
        labels = func(labels)
开发者ID:venkatsatish,项目名称:Recommendation-Engine,代码行数:33,代码来源:indexing.py

示例5: print

# 需要导入模块: from alchemyapi import AlchemyAPI [as 别名]
# 或者: from alchemyapi.AlchemyAPI import taxonomy [as 别名]
    for microformat in response['microformats']:
        print('Field: ', microformat['field'].encode('utf-8'))
        print('Data: ', microformat['data'])
        print('')

else:
    print('Error in microformats parsing call: ', response['statusInfo'])


print('')
print('')


print('#   Taxonomy  Example                      #')

response = alchemyapi.taxonomy('text', demo_text)

if response['status'] == 'OK':
    print('## Response Object ##')
    with open('taxonomy.js', 'w') as outfile:
        json.dump(response,outfile, indent =4)

    print('')
    print('## Categories ##')
    for category in response['taxonomy']:
        print(category['label'], ' : ', category['score'])
    print('')

else:
    print('Error in taxonomy call: ', response['statusInfo'])
开发者ID:metador,项目名称:alchemy,代码行数:32,代码来源:trying_api1.py

示例6: print

# 需要导入模块: from alchemyapi import AlchemyAPI [as 别名]
# 或者: from alchemyapi.AlchemyAPI import taxonomy [as 别名]
# combined
print('Checking combined . . . ')
response = alchemyapi.combined('text', test_text)
assert(response['status'] == 'OK')
response = alchemyapi.combined('html', test_html)
assert(response['status'] == 'ERROR')
response = alchemyapi.combined('url', test_url)
assert(response['status'] == 'OK')
print('Combined tests complete!')
print('')
print('')

# taxonomy
print('Checking taxonomy . . . ')
response = alchemyapi.taxonomy('text', test_text)
assert(response['status'] == 'OK')
response = alchemyapi.taxonomy('html', test_html, {'url': 'test'})
assert(response['status'] == 'OK')
response = alchemyapi.taxonomy('url', test_url)
assert(response['status'] == 'OK')
print('Taxonomy tests complete!')
print('')
print('')

# image
print('Checking image extraction . . . ')
response = alchemyapi.imageExtraction('text', test_text)
assert(response['status'] == 'ERROR')
response = alchemyapi.imageExtraction('html', test_html)
assert(response['status'] == 'ERROR')
开发者ID:hjorthjort,项目名称:Presens,代码行数:32,代码来源:tests.py

示例7: findTaxonomy

# 需要导入模块: from alchemyapi import AlchemyAPI [as 别名]
# 或者: from alchemyapi.AlchemyAPI import taxonomy [as 别名]
def findTaxonomy(text):
	alchemyapi = AlchemyAPI()
	response = alchemyapi.taxonomy('text', text)
	return response
开发者ID:gatemezing,项目名称:vocabDomain,代码行数:6,代码来源:vocabCategory.py

示例8: print

# 需要导入模块: from alchemyapi import AlchemyAPI [as 别名]
# 或者: from alchemyapi.AlchemyAPI import taxonomy [as 别名]
print("")


print("")
print("")
print("")
print("############################################")
print("#   Taxonomy  Example                      #")
print("############################################")
print("")
print("")

print("Processing text: ", demo_text)
print("")

response = alchemyapi.taxonomy("text", demo_text)

if response["status"] == "OK":
    print("## Response Object ##")
    print(json.dumps(response, indent=4))

    print("")
    print("## Categories ##")
    for category in response["taxonomy"]:
        print(category["label"], " : ", category["score"])
    print("")

else:
    print("Error in taxonomy call: ", response["statusInfo"])

print("")
开发者ID:jaybird23,项目名称:market_sentimentalism2,代码行数:33,代码来源:example.py

示例9: __init__

# 需要导入模块: from alchemyapi import AlchemyAPI [as 别名]
# 或者: from alchemyapi.AlchemyAPI import taxonomy [as 别名]
class AlchemyPost:

    def __init__(self, post_tumblr, post_id, consumer_key, consumer_secret, oauth_token, oauth_secret):
        self.post_tumblr = post_tumblr
        self.post_id = post_id
        self._init_tumblr(consumer_key, consumer_secret, oauth_token, oauth_secret)
        self._init_alchemy()

    def _init_tumblr(self, consumer_key, consumer_secret, oauth_token, oauth_secret):
        self._client = pytumblr.TumblrRestClient(consumer_key, consumer_secret, oauth_token, oauth_secret)    

    def _init_alchemy(self):
        self.alchemyapi = AlchemyAPI()
        self.content = {}

    def analyze_post(self):
        self.post = self._get_content_post()
        self._alchemy_entities()
        self._alchemy_keywords()
        self._alchemy_concepts()
        self._alchemy_sentiment()
        self._alchemy_relations()
        self._alchemy_category()
        self._alchemy_feeds()
        self._alchemy_taxonomy()

    def print_content(self):
        print(json.dumps(self.content, indent=4))

    def _get_content_post(self):
        print "*",
        infos = self._get_infos_post() 
        self.title = ''
        self.tags = []
        if 'tags' in infos:
            self.tags = infos['tags']
        
        if infos['type'] == 'text':
            return self._get_content_text(infos)
        if infos['type'] == 'quote':
            return self._get_content_quote(infos)
        return ''

    def _get_infos_post(self):
         infos = self._client.posts(self.post_tumblr, id=self.post_id)
         if 'posts' in infos and len(infos['posts'])>0:
            return infos['posts'][0]
         return {}

    def _get_content_text(self, infos):
        content = "<h1>" + str(infos['title']) + "</h1>"
        content += " <br>" + str(infos['body'])
        content += " <br>" + " ".join(infos['tags'])
        return content

    def _get_content_quote(self, infos):
        content = str(infos['text'])
        content += " <br>" + str(infos['source'])
        content += " <br>" + " ".join(infos['tags'])
        return content

    def _alchemy_entities(self):
        print ".",
        response = self.alchemyapi.entities('html', self.post)
        if response['status'] != 'OK':
            return False
        self.content['entities'] = response['entities']
        return True

    def _alchemy_keywords(self):
        print ".",
        response = self.alchemyapi.keywords('html', self.post)
        if response['status'] != 'OK':
            return False
        self.content['keywords'] = response['keywords']
        return True

    def _alchemy_concepts(self):
        print ".",
        response = self.alchemyapi.concepts('html', self.post)
        if response['status'] != 'OK':
            return False
        self.content['concepts'] = response['concepts']
        return True

    def _alchemy_sentiment(self):
        print ".",
        response = self.alchemyapi.sentiment('html', self.post)
        if response['status'] != 'OK':
            return False
        self.content['sentiment'] = response['docSentiment']
        return True

    def _alchemy_relations(self):
        print ".",
        response = self.alchemyapi.relations('html', self.post)
        if response['status'] != 'OK':
            return False
        self.content['relations'] = response['relations'] 
        return True
#.........这里部分代码省略.........
开发者ID:davidtysman,项目名称:py_alchemy_tumblr,代码行数:103,代码来源:alchemy_post.py

示例10: user_analysis_sentiments

# 需要导入模块: from alchemyapi import AlchemyAPI [as 别名]
# 或者: from alchemyapi.AlchemyAPI import taxonomy [as 别名]
def user_analysis_sentiments(request):
    if request.method == 'GET':
        print request.GET.get('user', '')
        user = request.GET.get('user', '')
        messages = []
        message = Message.objects.filter(user_send=user.decode("utf8"))
        for m in message:
            messages.append(m.message_text)
        text = ",".join(messages)
        alchemyapi = AlchemyAPI()

        #keywords
        response = alchemyapi.keywords('text', text, {'sentiment': 1})
        if response['status'] == 'OK':
            keywords = []
            for keyword in response['keywords']:
                keyword_text = keyword['text'].encode('utf-8')
                keyword_relevance = keyword['relevance']
                keyword_sentiment = keyword['sentiment']['type']
                key_word = {'keyword_text': keyword_text, 'keyword_relevance': keyword_relevance,
                            'keyword_sentiment': keyword_sentiment}
                keywords.append(key_word)
        else:
            print('Error in keyword extaction call: ', response['statusInfo'])

        response = alchemyapi.concepts('text', text)

        if response['status'] == 'OK':
            concepts = []
            for concept in response['concepts']:
                concept_text = concept['text']
                concept_relevance = concept['relevance']
                concept_entity = {'concept_text': concept_text, 'concept_relevance': concept_relevance}
                concepts.append(concept_entity)
        else:
            print('Error in concept tagging call: ', response['statusInfo'])

        response = alchemyapi.language('text', text)

        if response['status'] == 'OK':
            print(response['wikipedia'])
            language = response['language']
            iso_639_1 = response['iso-639-1']
            native_speakers = response['native-speakers']
            wikipedia = response['wikipedia']
            language_id = {'language': language, 'iso_639_1': iso_639_1, 'native_speakers': native_speakers, 'wikipedia': wikipedia}
        else:
            print('Error in language detection call: ', response['statusInfo'])

        response = alchemyapi.relations('text', text)

        if response['status'] == 'OK':
            relations = []
            for relation in response['relations']:
                if 'subject' in relation:
                    relation_subject_text = relation['subject']['text'].encode('utf-8')
                if 'action' in relation:
                    relation_action_text = relation['action']['text'].encode('utf-8')
                if 'object' in relation:
                    relation_object_text = relation['object']['text'].encode('utf-8')
                relation_entity = {'relation_subject_text': relation_subject_text,
                                   'relation_action_text': relation_action_text,
                                   'relation_object_text': relation_object_text}
                relations.append(relation_entity)
        else:
            print('Error in relation extaction call: ', response['statusInfo'])

        response = alchemyapi.category('text', text)

        if response['status'] == 'OK':
            print('text: ', response['category'])
            category = response['category']
            print('score: ', response['score'])
            score = response['score']
            categories = {'category': category, 'score': score}
        else:
            print('Error in text categorization call: ', response['statusInfo'])

        response = alchemyapi.taxonomy('text', text)

        if response['status'] == 'OK':
            taxonomies = []
            for category in response['taxonomy']:
                taxonomy_label = category['label']
                taxonomy_score = category['score']
                taxonomy = {'taxonomy_label': taxonomy_label, 'taxonomy_score': taxonomy_score}
                taxonomies.append(taxonomy)
        else:
            print('Error in taxonomy call: ', response['statusInfo'])

        response = alchemyapi.combined('text', text)

        if response['status'] == 'OK':
            print('## Response Object ##')
            print(json.dumps(response, indent=4))
            print('')

        user = {'user_name': 'LOL', 'keywords': keywords, 'concepts': concepts, 'language_id': language_id,
                'relations': relations, 'categories': categories, 'taxonomies': taxonomies}
        return HttpResponse(json.dumps(user), content_type="application/json")
开发者ID:pranav93,项目名称:Text-mining,代码行数:102,代码来源:views.py


注:本文中的alchemyapi.AlchemyAPI.taxonomy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。