Exemple #1
0
def test_entity_label(fx_loaded_entity: Entity, fx_unloaded_entity: Entity):
    assert isinstance(fx_loaded_entity.label, MultilingualText)
    assert fx_loaded_entity.label[Locale('ko')] == '신중현'
    assert fx_loaded_entity.label[Locale('zh-hant')] == '申重鉉'
    assert isinstance(fx_unloaded_entity.label, MultilingualText)
    assert fx_unloaded_entity.label[Locale('en')] == 'The Beatles'
    assert fx_unloaded_entity.label[Locale('ko')] == '비틀즈'
Exemple #2
0
def test_entity_pickle(fx_unloaded_entity: Entity, fx_loaded_entity: Entity):
    for entity in fx_unloaded_entity, fx_unloaded_entity:
        dumped = pickle.dumps(entity)
        loaded = pickle.loads(dumped)
        assert isinstance(loaded, Entity)
        assert loaded.state is entity.state
        assert loaded.label[Locale('en')] == entity.label[Locale('en')]
Exemple #3
0
def test_entity_label_description_three_chars_lang_codes(fx_client: Client):
    """
    Ensure that three-character language codes are handled
    """
    cbk_zam = fx_client.get(EntityId('Q33281'), load=True)
    assert isinstance(cbk_zam.label, MultilingualText)
    assert cbk_zam.label[Locale('ko')] == '차바카노어'
    assert Locale('cbk-zam') in cbk_zam.label
    assert isinstance(cbk_zam.description, MultilingualText)
    assert cbk_zam.description[Locale('en')] == \
        'Spanish-based creole language spoken in the Philippines'
    assert Locale('cbk-zam') not in cbk_zam.description
Exemple #4
0
def test_entity_description(fx_loaded_entity: Entity,
                            fx_unloaded_entity: Entity):
    assert isinstance(fx_loaded_entity.description, MultilingualText)
    assert fx_loaded_entity.description[Locale('ko')] == \
        '대한민국의 록 음악 싱어송라이터 및 기타리스트'
    assert fx_loaded_entity.description[Locale('ja')] == \
        '韓国のロックミュージシャン'
    assert isinstance(fx_unloaded_entity.description, MultilingualText)
    assert fx_unloaded_entity.description[Locale('en')] == \
        'English rock band'
    assert fx_unloaded_entity.description[Locale('ko')] == \
        '영국의 락 밴드'
def getWikidataLabel(uri, language):

    client = Client()
    entity = client.get(extractEntity(uri), load=True)
    try:
        label = entity.label[Locale(language)]
    except KeyError:
        label = ''
    return label
def test_multilingual_text_mapping(fx_multilingual_text: MultilingualText):
    mt = fx_multilingual_text
    assert set(mt) == {"ko", "ja", "zh-hans", "en"}
    assert len(mt) == 4
    assert Locale("ko") in mt
    assert Locale("ja") in mt
    assert Locale("zh-hans") in mt
    assert Locale("en") in mt
    assert Locale("ko-kp") not in mt
    assert Locale("zh-hant") not in mt
    assert Locale("en-gb") not in mt
    assert mt[Locale("ko")] == mt.get("ko") == '윤동주'
    assert mt[Locale("ja")] == mt.get("ja") == '尹東柱'
    assert mt[Locale("zh-hans")] == mt.get("zh-hans") == '尹东柱'
    assert mt[Locale("en")] == mt.get("en") == 'Yun Dong-ju'
    assert mt.get("ko-kp") is None
    assert mt.get('zh-hant') is None
    assert mt.get('en-gb') is None
Exemple #7
0
def test_client_pickle(fx_client: Client):
    dumped = pickle.dumps(fx_client)
    c = pickle.loads(dumped)
    entity = c.get(EntityId('Q1299'), load=True)
    assert isinstance(entity, Entity)
    assert entity.label[Locale('en')] == 'The Beatles'