예제 #1
0
def get_alchemy_subjects_remote(url):
    registry = getUtility(IRegistry)
    settings = registry.forInterface(ITagHelperSettingsSchema)
    api_key = settings.alchemy_api_key
    if api_key:
        alchemyObj = AlchemyAPI()
        alchemyObj.setAPIKey(api_key)
        try:
            result = alchemyObj.URLGetRankedConcepts(url)
            results += _list_alchemy_results(result)
            #result = alchemyObj.URLGetRankedKeywords(url)
            #results += _list_alchemy_results(result)
            #results = list(set(results))
            return results
        except:
            return results
    else:
        return results
예제 #2
0
def get_alchemy_subjects_remote(url):
    registry = getUtility(IRegistry)
    settings = registry.forInterface(ITagHelperSettingsSchema)
    api_key = settings.alchemy_api_key
    if api_key:
        alchemyObj = AlchemyAPI()
        alchemyObj.setAPIKey(api_key)
        try:
            result = alchemyObj.URLGetRankedConcepts(url)
            results += _list_alchemy_results(result)
            # result = alchemyObj.URLGetRankedKeywords(url)
            # results += _list_alchemy_results(result)
            # results = list(set(results))
            return results
        except:
            return results
    else:
        return results
예제 #3
0
def get_alchemy_subjects(text):
    registry = getUtility(IRegistry)
    settings = registry.forInterface(ITagHelperSettingsSchema)
    api_key = settings.alchemy_api_key
    relevance = settings.alchemy_relevance
    results = []
    if api_key:
        alchemyObj = AlchemyAPI()
        alchemyObj.setAPIKey(api_key)
        try:
            result = alchemyObj.TextGetRankedConcepts(text)
            results += _list_alchemy_results(result, relevance)
            #result = alchemyObj.TextGetRankedKeywords(text)
            #results += _list_alchemy_results(result)
            #results = list(set(results))
            return results
        except:
            return results
    else:
        return results
예제 #4
0
def get_alchemy_subjects(text):
    registry = getUtility(IRegistry)
    settings = registry.forInterface(ITagHelperSettingsSchema)
    api_key = settings.alchemy_api_key
    relevance = settings.alchemy_relevance
    results = []
    if api_key:
        alchemyObj = AlchemyAPI()
        alchemyObj.setAPIKey(api_key)
        try:
            result = alchemyObj.TextGetRankedConcepts(text)
            results += _list_alchemy_results(result, relevance)
            # result = alchemyObj.TextGetRankedKeywords(text)
            # results += _list_alchemy_results(result)
            # results = list(set(results))
            return results
        except:
            return results
    else:
        return results
    min_content_length = config['processing']['commands'] \
        ['text_extraction']['min_content_length']
    commands.append(TextExtractionCommand(te_client, min_content_length))

    # command: Parsing
    commands.append(ParsingCommand())

    # command: TermExtraction
    lemmatizer = Lemmatizer()
    min_term_count = config['processing']['commands'] \
        ['term_extraction']['min_term_count']
    commands.append(TermExtractionCommand(lemmatizer, min_term_count))

    # command: AlchemyEntityExtraction
    alchemy = AlchemyAPI()
    alchemy.setAPIKey(config['alchemyapi']['key'])
    alchemy_cache_collection = mcm.connection[cache_db][config['alchemyapi']['cache']['namespace']]
    alchemy_cache = MongoCache(alchemy_cache_collection)
    min_entity_count = config['processing']['commands'] \
        ['entity_extraction']['min_entity_count']
    commands.append(AlchemyEntityExtractionCommand(alchemy, alchemy_cache, min_entity_count))

    # command: Building
    commands.append(BuildingCommand())

    # start service clients
    te_client.connect()

    # set up the server
    handler = ProcessingHandler(commands)
    processor = ProcessingService.Processor(handler)