Ejemplo n.º 1
0
 def findLocation(self, params):
     '''
     Find location name from extracted text using Geograpy.
     '''
     file_name = params['file_name']
     text_content = QueryText(file_name)
     if text_content:
         e = extraction.Extractor(text=text_content)
         e.find_entities()
         status = IndexLocationName(file_name, e.places)
         if status[0]:
             return {
                 'job': 'find_location',
                 'status': 'successful',
                 'comment': 'Location/s found and indexed to Solr.'
             }
         else:
             return {
                 'job': 'find_location',
                 'status': 'unsuccessful',
                 'comment': status[1]
             }
     else:
         return {
             'job': 'find_location',
             'status': 'unsuccessful',
             'comment': 'Cannot extract text.'
         }
Ejemplo n.º 2
0
def find_places(message):
    extractor, flag = extraction.Extractor(text=message), True
    extractor.find_entities()
    available_places, place_from, place_to = extractor.places, None, None
    for place in available_places:
        if flag:
            flag, place_from = False, place
        else:
            flag, place_to = True, place

    return place_from, place_to
Ejemplo n.º 3
0
 def find_geograpy_locations(self, statement):
     """
     I actually extended geograpy to include more potential locations.
     I think we get a few more false postivies, so we need to do some filtering.
     TODO: Change the extraction script to include allow for supplying tags.
     Person and Organisation tags should be flagged as possible locations.`x
     :param statement:
     :return:
     """
     e = extraction.Extractor(text=statement)
     e.find_entities()
     return e.places
Ejemplo n.º 4
0
 def process_item(self, item, spider):
     try:
         adapter = ItemAdapter(item)
         extractor = extraction.Extractor(url=adapter['url'])
         extractor.find_geoEntities()
         places = list(set(extractor.places))
         adapter['places_mentioned'] = places
     except Exception:
         raise DropItem('Failed to extract '
                        'places mentioned in: '
                        + item['url'])
     return item
Ejemplo n.º 5
0
    def weather(self, source, location_params):
        """
        Jarvis will give you current weather in given city.
        If params are empty Jarvis will ask for name of city.

        :param source: speech_recognition.Microphone
        object of speech_recognition.Microphone,  which represents a physical microphone on the computer
        :param location_params: part of commend after "hot" word
        :return: None
        """

        base_url = "http://api.openweathermap.org/data/2.5/weather?"

        def get_weather(city):
            complete_url = f"{base_url}appid={self.api_key_weather}&q={city}"
            response = requests.get(complete_url).json()
            if response["cod"] != "404":
                weather = response["main"]

                current_temperature = round(pytemperature.k2c(weather["temp"]),
                                            2)
                current_temperature = f'{"minus" if current_temperature < 0 else ""}' + str(
                    current_temperature)
                current_pressure = weather["pressure"]

                current_humidity = weather["humidity"]

                weather_description = response["weather"][0]["description"]

                self.convert_text_to_speech(
                    f'Temperature (in celsius unit) = {current_temperature} '
                    f'atmospheric pressure (in hPa unit) = {current_pressure} '
                    f' humidity (in percentage) = {current_humidity} '
                    f'description = {weather_description}')
            else:
                self.convert_text_to_speech(JarvisPhrases.NO_CITY)

        city_extractor = extraction.Extractor(text=" ".join(location_params))

        while True:
            city_extractor.find_entities()
            if len(city_extractor.places) > 0:
                city = city_extractor.places[0]
                get_weather(city)
                break
            else:
                self.convert_text_to_speech(JarvisPhrases.WEATHER)
                audio = self.recognizer.listen(source)
                location = self.recognizer.recognize_google(audio)
                city_extractor.text = location
Ejemplo n.º 6
0
def test1():
    # peacefiles_w = [join(peace_dir_w,f) for f in listdir(peace_dir_w) if isfile(join(peace_dir_w, f)) and ".docx" in f]
    # for f in range(len(peacefiles_w)):
    #
    #     logging.info("Splitting: %s"%(peacefiles_w[f]))
    #
    #     doc = docx.Document(peacefiles_w[f])
    #     section = doc.sections[0]
    #     header = section.header
    #     #pdb.set_trace()
    #     for paragraph in header.paragraphs:
    #         print(paragraph.text) # or whatever you have in mind

    import geograpy
    import nltk
    from geograpy import extraction

    text = "Thyroid-associated orbitopathy (TO) is an autoimmune-\
    mediated orbital inflammation that can lead to disfigurement and blindness. \
    Multiple genetic loci have been associated with Graves' disease, but the genetic \
    basis for TO is largely unknown. British This japanese study aimed to identify loci associated with \
    TO in individuals with Graves' Mexican austrian japan Chinese disease, using a genome-wide association scan \
    (GWAS) for the first time to our knowledge in TO.Genome-wide association scan was \
    performed on pooled USA united states DNA from French britain an Australian Caucasian discovery cohort of 265 \
    participants with Graves' disease and TO (cases) and 147 patients with Graves' \
    mapisease without TO (controls)."

    from geotext import GeoText
    places = GeoText(text)

    print(places)

    e = extraction.Extractor(text=text)
    nes = nltk.ne_chunk(nltk.pos_tag(text))
    #print(nes)
    e.find_geoEntities()
    #print(e.find_geoEntities())
    country = e.places
    for s in range(len(country)):
        country[s] = stemmer.stem(country[s])

    # You can now access all of the places found by the Extractor
    print(country)
    #pdb.set_trace()
    print(stemmer.stem("Chinese"))
Ejemplo n.º 7
0
def find_location(request, file_name):
    '''
        Find location name from extracted text using Geograpy.
    '''
    if "none" in IndexStatus("locations", file_name):
        text_content = QueryText(file_name)
        if text_content:
            e = extraction.Extractor(text=text_content)
            e.find_entities()
            status = IndexLocationName(file_name, e.places)
            if status[0]:
                return HttpResponse(
                    status=200, content="Location/s found and index to Solr.")
            else:
                return HttpResponse(status=400, content=status[1])
        else:
            return HttpResponse(status=400, content="Cannot find location.")
    else:
        return HttpResponse(status=200, content="Loading...")
Ejemplo n.º 8
0
def extract_loc_name(t):
    e = extraction.Extractor(text=t)
    e.find_entities()
    return e.places