Beispiel #1
0
 def __init__(self, cities=True, communities=True, states=True):
     self.geotext = GeoText(config={"use_demo_data": False, "case_sensitive": False})
     if cities:
         self.add_cities_to_lookup()
     if communities:
         self.add_communities_to_lookup()
     if states:
         self.add_states_to_lookup()
Beispiel #2
0
def test_geotext_raises_on_empty_pool():
    config = GeoTextConfiguration(**{
        "use_demo_data": False,
        "case_sensitive": True
    })
    output = GeoText(config)

    with pytest.raises(MissingLookupDataError):
        output.extract(text)
Beispiel #3
0
def test_geotext_case_sensitive_demo_data():
    config = GeoTextConfiguration(**{
        "use_demo_data": True,
        "case_sensitive": False
    })
    geotext = GeoText(config)
    text = "berlin ist ne tolle stadt"
    output = geotext.extract(input_text=text)

    assert output["cities"]["Berlin"]["span_info"] == [(0, 6)]
    assert output["cities"]["Berlin"]["found_as"] == ["berlin"]
Beispiel #4
0
class GermanCityExtractor:

    def __init__(self, cities=True, communities=True, states=True):
        self.geotext = GeoText(config={"use_demo_data": False, "case_sensitive": False})
        if cities:
            self.add_cities_to_lookup()
        if communities:
            self.add_communities_to_lookup()
        if states:
            self.add_states_to_lookup()

    def add_cities_to_lookup(self):
        lookup_city = LookupData(name="german_cities", data=load_data_from_file(f"{path}/json/cities.json"))
        self.geotext.add(lookup_city, case_sensitive=False)

    def add_communities_to_lookup(self):
        lookup_community = LookupData(name="german_communities", data=load_data_from_file(f"{path}/json/communities.json"))
        self.geotext.add(lookup_community, case_sensitive=False)

    def add_states_to_lookup(self):
        lookup_state = LookupData(name="german_states", data=load_data_from_file(f"{path}/json/states.json"))
        self.geotext.add(lookup_state, case_sensitive=False)

    def extract_entities(self, msg):
        return self.geotext.extract(input_text=msg, span_info=False)
def test_geotext_with_script_added_to_non_word_boundaries():
    cyrillic = LookupData(name="test_1",
                          data={"Нижневартовск": ["Нижневартовск"]},
                          script="cyrillic")
    geotext = GeoText(config={"use_demo_data": False})
    geotext.add(cyrillic)

    text = """
    В Нижневартовском районе ограничили грузоподъемность на ледовых переправах
    Проехать по ледовой переправе сможет только транспорт весом не более 5 тонн.
    В связи с потеплением в Нижневартовском районе введено ограничение грузоподъемности на ледовых переправах.
    По направлению Нижневартовск - Вампугол – Былино, а также Белорусский - Ларьяк , Ларьяк -
    Чехломей - Большой Ларьяк, Былино - Зайцева Речка снижена грузоподъемность до 5 тонн.
    Лед на реках еще вполне толстый и переправа пригодна для эксплуатации, однако зимник начал подтаивать,
    орогу развезло. Потому принято решение снизить грузоподъемность на нём до 5 тонн, сообщает ОТРК «Югра».
    Всего на реках Югры работают 89 ледовых переправ. Их обычная грузоподъемность от 15 до 30 тонн. Отметим,
    что традиционно в середине апреля закрываются для движения автотранспорта все ледовые переправы.
    """

    result = geotext.extract(text, span_info=False)
    result["test_1"]["Нижневартовск"]["count"] == 1
Beispiel #6
0
import re 
from flashgeotext.geotext import GeoText
geotext = GeoText(use_demo_data=True)

def get_keyword(request, msg):
    global geotext
    try:
        city = None
        city = list(geotext.extract(input_text= msg, span_info= True)["cities"].keys())[0]
        if not city:
            city=""
        else:
            city = " in "+city
        d=msg.split(" ")
        if "sq" in msg:
            word = re.findall(r'[sq]\S*', msg)
            
        if "bhk" in msg:
            word = re.findall(r'[bhk]\S*',msg)
        get_data ="searching "+str(d[d.index(word[0])-1])+" "+str(word[0])+city
        answer_status = True
    except Exception as e:
        print(e)
        get_data = None
        answer_status = True

    return get_data, answer_status
Beispiel #7
0
def test_geotext_demo_data():
    geotext = GeoText()

    assert geotext.pool["cities"]
    assert geotext.pool["countries"]
def test_geotext_case_sensitive_demo_data():
    geotext = GeoText(config={"use_demo_data": True, "case_sensitive": False})
    text = "berlin ist ne tolle stadt"
    output = geotext.extract(input_text=text, span_info=True)

    assert output["cities"]["Berlin"]["span_info"] == [(0, 6)]
def test_geotext_raises_on_empty_pool():
    output = GeoText(config={"use_demo_data": False})

    with pytest.raises(MissingLookupDataError):
        output.extract(text)
Beispiel #10
0
def geotext():
    return GeoText(use_demo_data=True)
Beispiel #11
0
def geotext():
    return GeoText()