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


Python AlchemyAPI.title方法代码示例

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


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

示例1: render_article

# 需要导入模块: from alchemyapi import AlchemyAPI [as 别名]
# 或者: from alchemyapi.AlchemyAPI import title [as 别名]
def render_article(request):	
	#if current aricle has content field
	#render as is
	#else call alchemy and save content

	article_id = request.POST['articleData']
	article = Article.objects.filter(id = article_id)[0]

	print(article_id.encode('utf-8'))
	print(article.content.encode('utf-8'))
	if article.content:
		return render_to_response('article.html', {'id' : article.id, 'data' : article.content, 'titleText' : article.title})
	else:				
		testURL = article.url
		#Create AlchemyAPI Object
		alchemyapi = AlchemyAPI()
		response = alchemyapi.text('url', testURL)
		titleData = alchemyapi.title('url', testURL)
		authorData = alchemyapi.author('url', testURL)
		article.content = response['text'].encode('utf-8')
		article.title = titleData['title'].encode('utf-8')
		article.save()

		return render_to_response('article.html', {'id' : article.id, 'data' : response['text'].encode('utf-8'), 'titleText' : titleData['title'].encode('utf-8')}
 )
开发者ID:JoshuaKGoldberg,项目名称:StacheIt,代码行数:27,代码来源:views.py

示例2: Alchemy

# 需要导入模块: from alchemyapi import AlchemyAPI [as 别名]
# 或者: from alchemyapi.AlchemyAPI import title [as 别名]
class Alchemy(object):
  'Chama API para leitura de feeds Atom RSS'

  def __init__(self):
    #Chamador do AlchemyAPI
    self.alchemy_api = AlchemyAPI()

  def processa_html(self, link):

    #Retorna o texto limpo a partir de uma URL
    return self.alchemy_api.text('url', link)['text']

  def obtem_titulo(self, link):

    #Retorna o texto limpo a partir de uma URL
    return self.alchemy_api.title('url', link)['title']

  def obtem_entidades(self, texto):

    #Retorna as entidaades encontradas no texto
    return self.alchemy_api.entities('text', texto, {'sentiment': 1})
开发者ID:gdarruda,项目名称:leitor-noticias,代码行数:23,代码来源:Alchemy.py

示例3: print

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


print('')
print('')
print('')
print('############################################')
print('#   Title Extraction Example               #')
print('############################################')
print('')
print('')

print('Processing url: ', demo_url)
print('')

response = alchemyapi.title('url',demo_url)

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


	print('')
	print('## Title ##')
	print('title: ', response['title'].encode('utf-8'))
	print('')
else:
	print('Error in title extraction call: ', response['statusInfo'])


开发者ID:AditiKhullar,项目名称:tobuyornot,代码行数:29,代码来源:example.py

示例4: __init__

# 需要导入模块: from alchemyapi import AlchemyAPI [as 别名]
# 或者: from alchemyapi.AlchemyAPI import title [as 别名]
class Extraction:
    def __init__(self, url):
        self.alchemyAPI = AlchemyAPI()
        self.alchemyAPI.outputMode = 'json'
        self.url = url
        # must call extraction after initialization

    """
    Goes through all URL processing routines for the constructor-specified URL
    """
    def processText(self):
        text = self.__extractText(self.url)
        self.sentences = self.__sbdText(text)
        self.author    = self.__extractAuthor(self.url)
        self.title     = self.__extractTitle(self.url)


    """
    Calls AlchemyAPI to extract the text from the given article
    """
    def __extractText(self, url):
        if url is None or url == "":
            raise InputException("Invalid URL")

        response = self.alchemyAPI.text('url', url)
        if response['status'] != 'OK':
            warn(response['statusInfo'])

        return response['text'].encode('utf-8')

    """
    Calls AlchemyAPI to extract the author of the article.
    """
    def __extractAuthor(self, url):
        if url is None or url == "":
            raise InputException("Invalid URL")

        response = self.alchemyAPI.author('url', url)
        if response['status'] != 'OK':
            warn(response['statusInfo'])

        return response['author'].encode('utf-8')

    """
    Gets the article title with
    """
    def __extractTitle(self, url):
        if url is None or url == "":
            raise InputException("Invalid URL")

        response = self.alchemyAPI.title('url', url)
        if response['status'] != 'OK':
            warn(response['statusInfo'])
        return response['title'].encode('utf-8')


    """
    Applies a sentence boundary disambiguation algorithm to the extracted
    article text. We then have access to the individual sentences of the article.
    From there any quotes are removed, so sentiment analysis is performed on the writer's
    additions only.
    """
    def __sbdText(self, extractedText):
        import re
        sentenceEnders = re.compile(r"""
            # Split sentences on whitespace between them.
            (?:               # Group for two positive lookbehinds.
              (?<=[.!?])      # Either an end of sentence punct,
            | (?<=[.!?]['"])  # or end of sentence punct and quote.
            )                 # End group of two positive lookbehinds.
            (?<!  Mr\.   )    # Don't end sentence on "Mr."
            (?<!  Mrs\.  )    # Don't end sentence on "Mrs."
            (?<!  Jr\.   )    # Don't end sentence on "Jr."
            (?<!  Dr\.   )    # Don't end sentence on "Dr."
            (?<!  Prof\. )    # Don't end sentence on "Prof."
            (?<!  Sr\.   )    # Don't end sentence on "Sr."
            \s+               # Split on whitespace between sentences.
            """,
        re.IGNORECASE | re.VERBOSE)
        sentenceList = sentenceEnders.split(extractedText)

        """
        remove any quotes by recognizing ascii/unicode double sentences.
        any quotes within sentences are left, because this paraphrasing/choice
        is still somewhat indicative of possible bias
        """
        for sentence in list(sentenceList):
            if sentence[:3] == "“" or sentence[:1] == '"': # “ = unicode representation of slanted double quote
                sentenceList.remove(sentence)

        return sentenceList
开发者ID:noahgolmant,项目名称:TextExtraction,代码行数:93,代码来源:text_extraction.py

示例5: assert

# 需要导入模块: from alchemyapi import AlchemyAPI [as 别名]
# 或者: from alchemyapi.AlchemyAPI import title [as 别名]
response = alchemyapi.language('text', test_text);
assert(response['status'] == 'OK')
response = alchemyapi.language('html', test_html);
assert(response['status'] == 'OK')
response = alchemyapi.language('url', test_url);
assert(response['status'] == 'OK')
response = alchemyapi.language('random', test_url);
assert(response['status'] == 'ERROR') 	#invalid flavor
print('Language tests complete!')
print('')



#Title
print('Checking title . . . ')
response = alchemyapi.title('text', test_text);
assert(response['status'] == 'ERROR')	#only works for html and url content
response = alchemyapi.title('html', test_html);
assert(response['status'] == 'OK')
response = alchemyapi.title('url', test_url);
assert(response['status'] == 'OK')
print('Title tests complete!')
print('')



#Relations
print('Checking relations . . . ')
response = alchemyapi.relations('text', test_text);
assert(response['status'] == 'OK')
response = alchemyapi.relations('html', test_html);
开发者ID:AditiKhullar,项目名称:tobuyornot,代码行数:33,代码来源:tests.py

示例6: print

# 需要导入模块: from alchemyapi import AlchemyAPI [as 别名]
# 或者: from alchemyapi.AlchemyAPI import title [as 别名]
    print("Error in language detection call: ", response["statusInfo"])


print("")
print("")
print("")
print("############################################")
print("#   Title Extraction Example               #")
print("############################################")
print("")
print("")

print("Processing url: ", demo_url)
print("")

response = alchemyapi.title("url", demo_url)

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

    print("")
    print("## Title ##")
    print("title: ", response["title"].encode("utf-8"))
    print("")
else:
    print("Error in title extraction call: ", response["statusInfo"])


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


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