예제 #1
0
def test_calculate_tags(monkeypatch):
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    test_entity = {
        'claims': {
            'P31': [{
                'mainsnak': {
                    'datatype': 'wikibase-item',
                    'datavalue': {
                        'type': 'wikibase-entityid',
                        'value': {
                            'entity-type': 'item',
                            'id': 'Q15243209',
                            'numeric-id': 15243209
                        }
                    },
                },
            }],
        },
        'labels': {
            'en': {
                'language': 'en',
                'value': 'City Hall Historic District'
            },
        },
        'sitelinks': {},
    }
    tags = {
        'historic', 'boundary=protected_area', 'landuse=residential',
        'boundary=administrative', 'place', 'protect_class=22', 'admin_level'
    }
    item = Item(entity=test_entity, tags=tags)
    result = item.calculate_tags()
    assert 'building' not in result
    assert result == tags | {'leisure=park'}
예제 #2
0
def test_settlement_not_building():
    test_entity = {
        'claims': {},
        'labels': {'en': {'language': 'en', 'value': 'Capistrano Beach'}},
        'sitelinks': {},
    }

    tags = ['place=neighbourhood', 'landuse=residential']
    item = Item(entity=test_entity, tags=tags)

    assert item.calculate_tags() == set(tags)
예제 #3
0
def test_name_match_church(monkeypatch):
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    osm_tags = {
        'amenity': 'place_of_worship',
        'name': 'St Andrew',
    }

    entity = {
        "claims": {},
        "id": "Q23302351",
        "labels": {
            "en": {
                "value": "St Andrews, Great Finborough"
            }
        },
        "sitelinks": {},
    }

    categories = ['Church of England church buildings in Suffolk']

    item = Item(item_id=23302351,
                entity=entity,
                extract_names=["St Andrew's Church"],
                categories=categories)

    candidate = ItemCandidate(item=item, tags=osm_tags)

    for t in matcher.categories_to_tags(item.categories):
        item.tags.add(t)

    ret = matcher.check_item_candidate(candidate)
    assert 'reject' not in ret
예제 #4
0
def test_match_operator_at_start_of_name(monkeypatch):
    osm_tags = {
        'highway': 'services',
        'landuse': 'commercial',
        'name': 'Welcome Break Gordano Services',
        'operator': 'Welcome Break',
    }

    test_entity = {
        'claims': {},
        'labels': {
            'en': {
                'language': 'en',
                'value': 'Gordano services'
            },
        },
        'sitelinks': {}
    }

    tags = ['highway=services']
    item = Item(entity=test_entity, tags=tags)

    def mock_run_sql(cur, sql, debug):
        if not sql.startswith('select * from'):
            return []
        return [('polygon', 64002602, None, osm_tags, 0)]

    monkeypatch.setattr(matcher, 'run_sql', mock_run_sql)
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    mock_db = MockDatabase()

    candidates = matcher.find_item_matches(mock_db, item, 'prefix')
    assert len(candidates) == 1
예제 #5
0
def test_find_item_matches_pub(monkeypatch):
    osm_tags = {
        'amenity': 'university',
        'building': 'university',
        'name': 'Castle House',
    }

    test_entity = {
        'claims': {},
        'labels': {
            'en': {
                'language': 'en',
                'value': 'The Castle Inn'
            }
        },
        'sitelinks': {},
    }

    tags = ['building', 'amenity=pub']
    item = Item(entity=test_entity, tags=tags)

    def mock_run_sql(cur, sql, debug):
        return [('polygon', -295355, None, osm_tags, 12.75)]

    monkeypatch.setattr(matcher, 'run_sql', mock_run_sql)
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    mock_db = MockDatabase()

    candidates = matcher.find_item_matches(mock_db, item, 'prefix')
    assert len(candidates) == 0
예제 #6
0
def test_find_item_matches_mall(monkeypatch):
    osm_tags = {
        'landuse': 'retail',
        'name': 'Oxmoor Mall',
    }

    test_entity = {
        'claims': {},
        'labels': {
            'en': {
                'language': 'en',
                'value': 'Oxmoor Center'
            },
        },
        'sitelinks': {
            'enwiki': {
                'site': 'enwiki',
                'title': 'Oxmoor Center',
            }
        },
    }

    tags = ['landuse=retail']
    item = Item(entity=test_entity, tags=tags)

    candidates = find_item_matches(monkeypatch, osm_tags, item)
    assert len(candidates) == 1
    return
예제 #7
0
def test_railway_station_cafe_bad_match(monkeypatch):
    osm_tags = {
        'addr:city': 'Gillingham',
        'addr:housename': 'Gillingham (Kent) Railway Station',
        'addr:postcode': 'ME7 1XE',
        'addr:street': 'Railway Street',
        'amenity': 'cafe',
        'building': 'yes',
        'cuisine': 'coffee_shop',
        'name': 'BeeZoo Coffee Shop',
    }

    entity = {
        'claims': {},
        'labels': {
            'en': {
                'language': 'en',
                'value': "Gillingham railway station"
            },
        },
        'sitelinks': {
            'commonswiki': {
                'site': 'commonswiki',
                'title': 'Category:Gillingham (Kent) railway station',
            },
            'enwiki': {
                'site': 'enwiki',
                'title': 'Gillingham railway station (Kent)',
            },
            'nlwiki': {
                'site': 'nlwiki',
                'title': 'Station Gillingham (Kent)',
            },
            'simplewiki': {
                'site': 'simplewiki',
                'title': 'Gillingham (Kent) railway station',
            },
        },
    }

    tags = ['building=train_station', 'railway=station', 'railway=halt']
    item = Item(entity=entity, tags=tags)

    def mock_run_sql(cur, sql, debug):
        if not sql.startswith('select * from'):
            return []
        return [
            ('polygon', 1, None, osm_tags, 0),
        ]

    monkeypatch.setattr(matcher, 'run_sql', mock_run_sql)
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    mock_db = MockDatabase()

    candidates = matcher.find_item_matches(mock_db, item, 'prefix', debug=True)
    assert len(candidates) == 0
예제 #8
0
def test_prefer_tag_match_over_building_only_match(monkeypatch):
    tags1 = {
        'name': 'Shepperton',
        'network': 'National Rail',
        'railway': 'station',
    }
    tags2 = {'building': 'yes', 'name': 'Shepperton Station'}

    entity = {
        'claims': {},
        'labels': {
            'en': {
                'language': 'en',
                'value': 'Shepperton railway station'
            },
            'nl': {
                'language': 'nl',
                'value': 'station Shepperton'
            },
        },
        'sitelinks': {},
    }

    tags = ['building=train_station', 'railway=station', 'building']
    item = Item(entity=entity, tags=tags)

    def mock_run_sql(cur, sql, debug):
        if not sql.startswith('select * from'):
            return []
        return [
            ('point', 3397249904, None, tags1, 26.78),
            ('polygon', 246812406, None, tags2, 0),
        ]

    monkeypatch.setattr(matcher, 'run_sql', mock_run_sql)
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    mock_db = MockDatabase()

    candidates = matcher.find_item_matches(mock_db, item, 'prefix', debug=True)
    assert len(candidates) == 1
    c = candidates[0]
    del c['name_match']
    assert c == {
        'osm_type': 'node',
        'osm_id': 3397249904,
        'name': None,
        'tags': tags1,
        'dist': 26.78,
        'planet_table': 'point',
        'src_id': 3397249904,
        'geom': None,
        'identifier_match': False,
        'address_match': None,
        'matching_tags': {'railway=station'}
    }
예제 #9
0
def test_cottage_church_bad_match(monkeypatch):
    church_tags = {
        'amenity': 'place_of_worship',
        'building': 'yes',
        'denomination': 'anglican',
        'name': 'Saint Anne',
        'religion': 'christian',
    }

    entity = {
        'claims': {},
        'labels': {
            'en': {
                'language': 'en',
                'value': "St Anne's Cottage"
            },
        },
        'sitelinks': {}
    }

    cottage_item = {
        'claims': {},
        'labels': {
            'en': {
                'language': 'en',
                'value': "cottage"
            },
        },
        'sitelinks': {}
    }

    isa = IsA(item_id=5783996, entity=cottage_item)

    tags = ['building', 'building=yes']
    item = Item(entity=entity, tags=tags, isa=[isa])

    def mock_run_sql(cur, sql, debug):
        if not sql.startswith('select * from'):
            return []
        return [
            ('polygon', 111491387, None, church_tags, 0),
        ]

    monkeypatch.setattr(matcher, 'run_sql', mock_run_sql)
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    mock_db = MockDatabase()

    candidates = matcher.find_item_matches(mock_db, item, 'prefix', debug=True)
    assert len(candidates) == 0
예제 #10
0
def test_find_item_matches_parking(monkeypatch):
    osm_tags = {
        'amenity': 'parking',
        'building': 'yes',
        'fee': 'yes',
        'name': 'PlayhouseSquare Parking',
        'operator': 'PlayhouseSquare',
        'parking': 'multi-storey',
        'supervised': 'yes',
    }

    test_entity = {
        'claims': {},
        'labels': {
            'en': {
                'language': 'en',
                'value': 'Playhouse Square'
            },
            'de': {
                'language': 'de',
                'value': 'Playhouse Square'
            },
        },
        'sitelinks': {
            'commonswiki': {
                'site': 'commonswiki',
                'title': 'Category:Playhouse Square',
            },
            'enwiki': {
                'site': 'enwiki',
                'title': 'Playhouse Square',
            }
        },
    }

    tags = ['amenity=arts_centre', 'building']
    item = Item(entity=test_entity, tags=tags)

    def mock_run_sql(cur, sql, debug):
        if not sql.startswith('select * from'):
            return []
        return [('polygon', 116620439, None, osm_tags, 253.7)]

    monkeypatch.setattr(matcher, 'run_sql', mock_run_sql)
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    mock_db = MockDatabase()

    candidates = matcher.find_item_matches(mock_db, item, 'prefix')
    assert len(candidates) == 0
예제 #11
0
def test_alcatraz_lighthouse(monkeypatch):
    lighthouse_tags = {
        'alt_name': 'United States Coast Guard Lighthouse',
        'building': 'yes',
        'man_made': 'lighthouse',
        'name': 'Alcatraz Island Lighthouse',
        'start_date': '1909',
        'wikidata': 'Q4712967',
    }
    island_tags = {'name': 'Alcatraz Island', 'tourism': 'attraction'}

    test_entity = {
        'claims': {},
        'labels': {
            'en': {
                'language': 'en',
                'value': 'Alcatraz Island Light'
            },
        },
        'sitelinks': {
            'commonswiki': {
                'site': 'commonswiki',
                'title': 'Category:Alcatraz Island Lighthouse'
            },
            'enwiki': {
                'site': 'enwiki',
                'title': 'Alcatraz Island Light'
            },
        },
    }

    tags = ['tourism=attraction', 'building', 'man_made=lighthouse']
    item = Item(entity=test_entity, tags=tags)

    def mock_run_sql(cur, sql, debug):
        if not sql.startswith('select * from'):
            return []
        return [
            ('point', 265562462, None, island_tags, 151),
            ('polygon', 99202294, None, lighthouse_tags, 0),
        ]

    monkeypatch.setattr(matcher, 'run_sql', mock_run_sql)
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    mock_db = MockDatabase()

    candidates = matcher.find_item_matches(mock_db, item, 'prefix', debug=True)
    assert len(candidates) == 2
예제 #12
0
def test_stable_shouldnt_match_house(monkeypatch):
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    osm_tags = {
        'addr:street': 'Back Lane',
        'building': 'house',
        'name': 'Nazeing Park',
    }

    entity = {
        'claims': {
            'P31': [{
                'mainsnak': {
                    'datavalue': {
                        'value': {
                            'id': 'Q214252'
                        }
                    }
                },
            }],
        },
        'labels': {
            'en': {
                'value': 'Stable At Nazeing Park'
            }
        },
        'sitelinks': {},
    }

    cottage_item = {
        'claims': {},
        'labels': {
            'en': {
                'language': 'en',
                'value': "stable"
            },
        },
        'sitelinks': {}
    }

    isa = IsA(item_id=214252, entity=cottage_item)

    tags = ['building=stable']
    item = Item(item_id=26404858, entity=entity, tags=tags, isa=[isa])

    candidate = ItemCandidate(item=item, tags=osm_tags)

    ret = matcher.check_item_candidate(candidate)
    assert 'reject' in ret
예제 #13
0
def test_school_shouldnt_match_church(monkeypatch):
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    osm_tags = {
        'amenity': 'place_of_worship',
        'building': 'yes',
        'denomination': 'roman_catholic',
        'name': 'Our Lady of Lourdes',
        'religion': 'christian',
    }

    entity = {
        'claims': {
            'P31': [{
                'mainsnak': {
                    'datavalue': {
                        'value': {
                            'id': 'Q3914'
                        }
                    }
                },
            }],
        },
        'labels': {
            'en': {
                'value': 'Our Lady of Lourdes School'
            }
        },
        'sitelinks': {},
    }

    categories = [
        'Catholic primary schools in the Archdiocese of Westminster',
        'Primary schools in the London Borough of Enfield',
        'Voluntary aided schools in London'
    ]

    item = Item(item_id=7110870,
                entity=entity,
                extract_names=[],
                categories=categories)

    candidate = ItemCandidate(item=item, tags=osm_tags)

    for t in matcher.categories_to_tags(item.categories):
        item.tags.add(t)

    ret = matcher.check_item_candidate(candidate)
    assert 'reject' in ret
예제 #14
0
def test_item_first_paragraph():
    extract = '<p><b>Gotham Bar and Grill</b> is a New American restaurant located at 12 East 12th Street (between Fifth Avenue and University Place), in Greenwich Village in Manhattan, in New York City. It opened in 1984.</p>\n<p>It is owned by American chef Alfred Portale, one of the founders of New American cuisine, who is also its chef. He arrived at the restaurant in 1985.</p>\n<p></p>'
    item = Item(extracts={'enwiki': extract})
    first = item.first_paragraph()
    assert first == '<p><b>Gotham Bar and Grill</b> is a New American restaurant located at 12 East 12th Street (between Fifth Avenue and University Place), in Greenwich Village in Manhattan, in New York City. It opened in 1984.</p>'

    extract = '''<p><span></span></p>

<p><b>IFC Center</b> is an art house movie theater in Greenwich Village, New York City in the United States of America. Located at 323 Sixth Avenue (Also known as 323 Avenue of the Americas) at West 3rd Street, it was formerly the Waverly Theater, a well- known art house movie theater. IFC Center is owned by AMC Networks (known until July 1, 2011 as Rainbow Media), the entertainment company that owns the cable channels AMC, IFC, WE tv and Sundance Channel and the film company IFC Films.</p>
<p>AMC Networks has positioned the theater as an extension of its cable channel IFC (Independent Film Channel) as IFC will own the building.</p>
<p></p>'''
    item = Item(extracts={'enwiki': extract})
    first = item.first_paragraph()
    assert first == '<p><b>IFC Center</b> is an art house movie theater in Greenwich Village, New York City in the United States of America. Located at 323 Sixth Avenue (Also known as 323 Avenue of the Americas) at West 3rd Street, it was formerly the Waverly Theater, a well- known art house movie theater. IFC Center is owned by AMC Networks (known until July 1, 2011 as Rainbow Media), the entertainment company that owns the cable channels AMC, IFC, WE tv and Sundance Channel and the film company IFC Films.</p>'

    extract = '''<p class="mw-empty-elt">
</p>
<p><b>280 Broadway</b> – also known as the <b>A.T. Stewart Dry Goods Store</b>, the <b>Marble Palace</b>, and the <b>Sun Building</b> – a historic building located between Chambers and Reade Streets in the Civic Center district of Manhattan, New York City, was the first commercial building in the Italianate style in New York City, and is considered the site of one of the nation's first department stores.  It was designed by John B. Snook of Joseph Trench &amp; Company, with later additions by other architects.  It was built for the A. T. Stewart Company, which opened New York's first department store in it. It later housed the original <i>New York Sun</i> newspaper (1833-1950) and is now the central offices for the New York City Department of Buildings.</p><p>The building was declared a National Historic Landmark in 1965, and was designated a New York City landmark in 1986.</p>'''
    item = Item(extracts={'enwiki': extract})
    first = item.first_paragraph()
    assert first == "<p><b>280 Broadway</b> – also known as the <b>A.T. Stewart Dry Goods Store</b>, the <b>Marble Palace</b>, and the <b>Sun Building</b> – a historic building located between Chambers and Reade Streets in the Civic Center district of Manhattan, New York City, was the first commercial building in the Italianate style in New York City, and is considered the site of one of the nation's first department stores.  It was designed by John B. Snook of Joseph Trench &amp; Company, with later additions by other architects.  It was built for the A. T. Stewart Company, which opened New York's first department store in it. It later housed the original <i>New York Sun</i> newspaper (1833-1950) and is now the central offices for the New York City Department of Buildings.</p>"
예제 #15
0
def test_station_shouldnt_match_school(monkeypatch):
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    osm_tags = {
        'addr:city': 'Cummersdale',
        'building': 'school',
        'name': 'Cummersdale School',
    }

    entity = {
        'claims': {
            'P31': [{
                'mainsnak': {
                    'datavalue': {
                        'value': {
                            'id': 'Q55488'
                        }
                    }
                },
            }],
        },
        'labels': {
            'en': {
                'value': 'Cummersdale railway station'
            }
        },
        'sitelinks': {},
    }

    categories = ['Disused railway stations in Cumbria']

    item = Item(item_id=5194098,
                entity=entity,
                extract_names=['Cummersdale'],
                categories=categories)

    candidate = ItemCandidate(item=item, tags=osm_tags)

    for t in matcher.categories_to_tags(item.categories):
        item.tags.add(t)

    ret = matcher.check_item_candidate(candidate)
    assert 'reject' in ret
예제 #16
0
def test_item_first_paragraph():
    extract = '<p><b>Gotham Bar and Grill</b> is a New American restaurant located at 12 East 12th Street (between Fifth Avenue and University Place), in Greenwich Village in Manhattan, in New York City. It opened in 1984.</p>\n<p>It is owned by American chef Alfred Portale, one of the founders of New American cuisine, who is also its chef. He arrived at the restaurant in 1985.</p>\n<p></p>'
    item = Item(extracts={'enwiki': extract})
    first = item.first_paragraph()
    assert first == '<p><b>Gotham Bar and Grill</b> is a New American restaurant located at 12 East 12th Street (between Fifth Avenue and University Place), in Greenwich Village in Manhattan, in New York City. It opened in 1984.</p>'

    extract = '''<p><span></span></p>

<p><b>IFC Center</b> is an art house movie theater in Greenwich Village, New York City in the United States of America. Located at 323 Sixth Avenue (Also known as 323 Avenue of the Americas) at West 3rd Street, it was formerly the Waverly Theater, a well- known art house movie theater. IFC Center is owned by AMC Networks (known until July 1, 2011 as Rainbow Media), the entertainment company that owns the cable channels AMC, IFC, WE tv and Sundance Channel and the film company IFC Films.</p>
<p>AMC Networks has positioned the theater as an extension of its cable channel IFC (Independent Film Channel) as IFC will own the building.</p>
<p></p>'''
    item = Item(extracts={'enwiki': extract})
    first = item.first_paragraph()
    assert first == '<p><b>IFC Center</b> is an art house movie theater in Greenwich Village, New York City in the United States of America. Located at 323 Sixth Avenue (Also known as 323 Avenue of the Americas) at West 3rd Street, it was formerly the Waverly Theater, a well- known art house movie theater. IFC Center is owned by AMC Networks (known until July 1, 2011 as Rainbow Media), the entertainment company that owns the cable channels AMC, IFC, WE tv and Sundance Channel and the film company IFC Films.</p>'
예제 #17
0
def test_name_and_location_better_than_address_and_building(monkeypatch):
    tower_tags = {'name': 'Reunion Tower', 'tourism': 'attraction'}
    hotel_tags = {
        'addr:housenumber': '300',
        'addr:street': 'Reunion Boulevard',
        'building': 'hotel'
    }

    test_entity = {
        'claims': {},
        'labels': {
            'en': {
                'language': 'en',
                'value': 'Reunion Tower'
            },
        },
        'sitelinks': {},
    }

    extract = (
        '<p><b>Reunion Tower</b> is a 561 ft (171 m) observation tower and ' +
        'one of the most recognizable landmarks in Dallas, Texas. Located at '
        +
        '300 Reunion Boulevard in the Reunion district of downtown Dallas.</p>'
    )

    tags = ['man_made=tower', 'building=tower', 'height']
    item = Item(entity=test_entity, tags=tags, extract=extract)

    def mock_run_sql(cur, sql, debug):
        if sql.startswith('select * from'):
            return [('polygon', 29191381, None, hotel_tags, 0)]
        else:
            return [('point', 600482843, None, tower_tags, 7)]

    monkeypatch.setattr(matcher, 'run_sql', mock_run_sql)
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    mock_db = MockDatabase()

    candidates = matcher.find_item_matches(mock_db, item, 'prefix', debug=True)
    assert len(candidates) == 2
예제 #18
0
def test_find_item_matches(monkeypatch):
    osm_tags = {
        'height': '44.9',
        'building': 'yes',
        'addr:street': 'West 37th Street',
        'nycdoitt:bin': '1087066',
        'addr:postcode': '10018',
        'addr:housenumber': '450',
    }

    def mock_run_sql(cur, sql, debug):
        if not sql.startswith('select * from'):
            return []
        return [('polygon', 265273006, None, osm_tags, 0.0)]

    monkeypatch.setattr(matcher, 'run_sql', mock_run_sql)
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    extract = '''<p>The <b>Baryshnikov Arts Center</b> (<b>BAC</b>) is a foundation and arts complex opened by Mikhail Baryshnikov in 2005 at 450 West 37th Street between Ninth and Tenth Avenues in the Hell's Kitchen neighborhood of Manhattan, New York City. The top three floors of the complex are occupied by the Baryshnikov Arts Center, which provides space and production facilities for dance, music, theater, film, and visual arts. The building also houses the Orchestra of St. Luke's DiMenna Center for Classical Music.</p>'''
    item = Item(entity=entity, tags=['building'], extract=extract)

    mock_db = MockDatabase()

    expect = {
        'osm_type': 'way',
        'osm_id': 265273006,
        'name': None,
        'tags': osm_tags,
        'dist': 0.0,
        'planet_table': 'polygon',
        'src_id': 265273006,
        'geom': None,
        'identifier_match': False,
        'address_match': True,
        'name_match': {},
        'matching_tags': {'building'},
    }

    candidates = matcher.find_item_matches(mock_db, item, 'prefix')
    assert len(candidates) == 1
    assert candidates[0] == expect
예제 #19
0
def test_lifeboat_station_church_bad_match(monkeypatch):
    osm_tags = {
        'amenity': 'place_of_worship',
        'building': 'yes',
        'denomination': 'anglican',
        'name': "St Agnes'",
        'religion': 'christian',
    }

    entity = {
        'claims': {},
        'labels': {
            'en': {
                'language': 'en',
                'value': 'St Agnes Lifeboat Station'
            },
        },
        'sitelinks': {}
    }

    tags = [
        'amenity=lifeboat_station', 'building', 'building=yes',
        'emergency=lifeboat_station'
    ]
    item = Item(entity=entity, tags=tags)

    def mock_run_sql(cur, sql, debug):
        if not sql.startswith('select * from'):
            return []
        return [
            ('polygon', 234155614, None, osm_tags, 0),
        ]

    monkeypatch.setattr(matcher, 'run_sql', mock_run_sql)
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    mock_db = MockDatabase()

    candidates = matcher.find_item_matches(mock_db, item, 'prefix', debug=True)
    assert len(candidates) == 0
예제 #20
0
def test_castle_station_bad_match(monkeypatch):
    osm_tags = {
        'building': 'train_station',
        'name': 'Holyhead',
        'name:cy': 'Caergybi',
        'railway': 'station',
    }

    entity = {
        'claims': {},
        'labels': {
            'en': {
                'language': 'en',
                'value': 'Caer Gybi'
            },
            'cy': {
                'language': 'cy',
                'value': 'Caer Gybi (caer)'
            },
        },
        'sitelinks': {}
    }

    tags = ['historic=castle', 'building']
    item = Item(entity=entity, tags=tags)

    def mock_run_sql(cur, sql, debug):
        if not sql.startswith('select * from'):
            return []
        return [
            ('polygon', 158252670, None, osm_tags, 0),
        ]

    monkeypatch.setattr(matcher, 'run_sql', mock_run_sql)
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    mock_db = MockDatabase()

    candidates = matcher.find_item_matches(mock_db, item, 'prefix', debug=True)
    assert len(candidates) == 0
예제 #21
0
def test_hamlet_shouldnt_match_house(monkeypatch):
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    osm_tags = {'name': 'Pednor House', 'place': 'residence'}

    entity = {
        'claims': {
            'P31': [{
                'mainsnak': {
                    'datavalue': {
                        'value': {
                            'id': 'Q5084'
                        }
                    }
                },
            }],
        },
        'labels': {
            'en': {
                'value': 'Pednor'
            }
        },
        'sitelinks': {},
    }

    categories = ['Hamlets in Buckinghamshire']

    item = Item(item_id=7159326,
                entity=entity,
                extract_names=['Pednor'],
                categories=categories)

    candidate = ItemCandidate(item=item, tags=osm_tags)

    for t in matcher.categories_to_tags(item.categories):
        item.tags.add(t)

    ret = matcher.check_item_candidate(candidate)
    assert 'reject' in ret
예제 #22
0
def test_add_tags_to_items(app):
    place = simple_place()

    item = Item(item_id=1,
                tags={'amenity=library'},
                location='Point(-2.62071 51.454)',
                categories=['Museums'])
    place.items.append(item)
    database.session.add(place)
    database.session.commit()

    place.add_tags_to_items()
    expect = {
        'tourism=attraction',
        'tourism=gallery',
        'tourism=museum',
        'historic=museum',
        'building=museum',
        'amenity=library',
    }

    assert filter_tags(item.tags) == expect
    assert filter_tags(place.all_tags) == expect
예제 #23
0
def test_find_item_matches_mall(monkeypatch):
    osm_tags = {
        'landuse': 'retail',
        'name': 'Oxmoor Mall',
    }

    test_entity = {
        'claims': {},
        'labels': {
            'en': {
                'language': 'en',
                'value': 'Oxmoor Center'
            },
        },
        'sitelinks': {
            'enwiki': {
                'site': 'enwiki',
                'title': 'Oxmoor Center',
            }
        },
    }

    tags = ['landuse=retail']
    item = Item(entity=test_entity, tags=tags)

    def mock_run_sql(cur, sql, debug):
        if not sql.startswith('select * from'):
            return []
        return [('polygon', 59847542, None, osm_tags, 0)]

    monkeypatch.setattr(matcher, 'run_sql', mock_run_sql)
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    mock_db = MockDatabase()

    candidates = matcher.find_item_matches(mock_db, item, 'prefix')
    assert len(candidates) == 1
예제 #24
0
def test_church_is_not_school(monkeypatch):
    test_entity = {
        'claims': {},
        'labels': {
            'en': {
                'language': 'en',
                'value': "St. Paul's Catholic Church"
            },
        },
        'sitelinks': {},
    }

    tags = ['amenity=place_of_worship', 'religion=christian']
    item = Item(entity=test_entity, tags=tags)

    osm_tags = {
        'name': "Saint Paul's Catholic School",
        'height': '12',
        'amenity': 'school',
        'building': 'school',
        'religion': 'christian',
        'denomination': 'catholic',
    }

    def mock_run_sql(cur, sql, debug):
        if not sql.startswith('select * from'):
            return []
        return [('polygon', 1, None, osm_tags, 0)]

    monkeypatch.setattr(matcher, 'run_sql', mock_run_sql)
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    mock_db = MockDatabase()

    candidates = matcher.find_item_matches(mock_db, item, 'prefix')
    assert len(candidates) == 0
예제 #25
0
def test_no_match_cottage(monkeypatch):
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    osm_tags = {
        'addr:housename': 'Stonehaven',
        'addr:housenumber': '6',
        'addr:street': 'High St',
        'building': 'yes',
    }

    entity = {
        'claims': {
            'P31': [{
                'mainsnak': {
                    'datavalue': {
                        'value': {
                            'id': 'Q5783996'
                        }
                    }
                },
            }],
        },
        'labels': {
            'en': {
                'value': 'Stonehaven Cottage'
            }
        },
        'sitelinks': {},
    }

    item = Item(item_id=26573554, entity=entity, tags=['building'])

    candidate = ItemCandidate(item=item, tags=osm_tags)

    ret = matcher.check_item_candidate(candidate)
    assert 'reject' in ret
예제 #26
0
def test_church_pub_bad_match(monkeypatch):
    osm_tags = {
        'amenity': 'pub',
        'building': 'commercial',
        'name': 'The Broadwater',
    }

    entity = {
        'claims': {
            'P373': [{
                'mainsnak': {
                    'datavalue': {
                        'value': 'Broadwater Church, West Sussex'
                    },
                }
            }]
        },
        'labels': {
            'en': {
                'language': 'en',
                'value': "St. Mary's Church, Broadwater"
            },
        },
        'sitelinks': {
            'commonswiki': {
                'site': 'commonswiki',
                'title': 'Category:Broadwater Church, West Sussex',
            },
            'enwiki': {
                'site': 'enwiki',
                'title': "St Mary's Church, Broadwater",
            }
        },
    }

    tags = [
        'religion=christian', 'building=yes', 'building',
        'amenity=place_of_worship', 'building=shrine', 'building=temple',
        'building=church'
    ]
    item = Item(entity=entity, tags=tags)

    def place_names():
        return ['West Sussex']

    monkeypatch.setattr(item, 'place_names', place_names)

    def mock_run_sql(cur, sql, debug):
        if not sql.startswith('select * from'):
            return []
        return [
            ('polygon', 91013361, None, osm_tags, 0),
        ]

    monkeypatch.setattr(matcher, 'run_sql', mock_run_sql)
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    mock_db = MockDatabase()

    candidates = matcher.find_item_matches(mock_db, item, 'prefix', debug=True)
    assert len(candidates) == 0
예제 #27
0
def test_item_match_sql(monkeypatch):
    item = Item(entity=entity, tags=['building'])
    monkeypatch.setattr(matcher, 'current_app', MockApp)
    sql = matcher.item_match_sql(item, 'test')
    assert "(tags ? 'building')" in sql
예제 #28
0
def test_embassy_no_match(monkeypatch):
    osm_tags1 = {
        'name': 'Consulate General of Switzerland in San Francisco',
        'amenity': 'embassy',
        'country': 'CH',
        'addr:city': 'San Francisco',
        'addr:state': 'CA',
        'addr:street': 'Montgomery Street',
        'addr:postcode': '94104',
        'addr:housenumber': '456',
    }

    osm_tags2 = {
        'addr:housenumber': '456',
        'addr:street': 'Montgomery Street',
        'building': 'yes',
        'building:levels': '22',
        'height': '114',
        'name': 'Consulate General of Switzerland in San Francisco',
    }

    en_label = 'Consulate General of Israel to the Pacific Northwest Region'
    test_entity = {
        'claims': {
            'P969': [{
                'mainsnak': {
                    'datavalue': {
                        'value': '456 Montgomery Street Suite #2100'
                    },
                },
            }],
            'P17': [{
                'mainsnak': {
                    'datavalue': {
                        'value': {
                            'id': 'Q30'
                        }
                    }
                },
            }],
            'P137': [{
                'mainsnak': {
                    'datavalue': {
                        'value': {
                            'id': 'Q801'
                        }
                    }
                },
            }],
        },
        'labels': {
            'en': {
                'language': 'en',
                'value': en_label
            }
        },
        'sitelinks': {},
    }

    extract = (
        '<p>The <b>Consulate General of Israel to the Pacific Northwest ' +
        'Region</b>, is one of Israel’s diplomatic missions abroad, located at '
        +
        '456 Montgomery Street Suite #2100 in San Francisco, California, United '
        + 'States of America in the Financial District.</p>')

    tags = ['amenity=embassy']
    item = Item(entity=test_entity, tags=tags, extract=extract)

    def mock_run_sql(cur, sql, debug):
        if not sql.startswith('select * from'):
            return []
        return [('point', 1, None, osm_tags1, 0),
                ('polygon', 2, None, osm_tags2, 0)]

    monkeypatch.setattr(matcher, 'run_sql', mock_run_sql)
    monkeypatch.setattr(matcher, 'current_app', MockApp)

    mock_db = MockDatabase()

    candidates = matcher.find_item_matches(mock_db, item, 'prefix')
    assert len(candidates) == 0
예제 #29
0
def test_bad_building_match():

    item = Item()

    assert not matcher.bad_building_match({}, {}, item)

    name_match = {'name': [('good', 'Test', [('label', 'en')])]}

    osm_tags = {'amenity': 'parking'}
    assert matcher.bad_building_match(osm_tags, name_match, item)

    assert not matcher.bad_building_match({}, name_match, item)

    name_match = {'name': [('both_trimmed', 'Test', [('label', 'en')])]}
    assert matcher.bad_building_match({}, name_match, item)

    name_match = {
        'name': [('both_trimmed', 'Test', [('label', 'en')])],
        'old_name': [('good', 'Test', [('label', 'en')])]
    }

    assert not matcher.bad_building_match({}, name_match, item)

    name_match = {
        'name': [('both_trimmed', 'Test', [('label', 'en')])],
        'operator': [('wikidata_trimmed', 'Test', [('label', 'en')])]
    }

    assert matcher.bad_building_match({}, name_match, item)

    osm_tags = {
        'name': 'Westland London',
        'shop': 'furniture',
        'building': 'yes',
        'addr:street': 'Leonard Street',
        'addr:postcode': 'EC2A 4QX',
        'addr:housename': "St. Michael's Church",
    }

    name_match = {
        'addr:housename': [('good', 'Church Of St Michael', [('label', 'en')])]
    }

    assert not matcher.bad_building_match(osm_tags, name_match, item)

    osm_tags = {
        'addr:city': 'Birmingham',
        'addr:housenumber': '42',
        'addr:postcode': 'B9 5QF',
        'addr:street': 'Yardley Green Road',
        'amenity': 'place_of_worship',
        'building': 'yes',
        'heritage': '2',
        'heritage:operator': 'Historic England',
        'listed_status': 'Grade II',
        'name': 'Masjid Noor-Us-Sunnah',
        'previous_name': 'Samson & Lion',
        'previous_use': 'pub',
        'religion': 'muslim',
    }

    name_match = {
        'previous_name': [('wikidata_trimmed', 'Samson And Lion Public House',
                           [('label', 'en')])]
    }

    assert not matcher.bad_building_match(osm_tags, name_match, item)