Ejemplo n.º 1
0
    def test_resolve_property_path(self):
        self.assertEqual(self.resolve('P297', 'Q142'),
                         [IdentifierValue(value='FR')])

        self.assertTrue(
            IdentifierValue(value='FR') in self.resolve('Afr', 'Q142'))

        self.assertEqual(self.resolve('P17/P297', 'Q83259'),
                         [IdentifierValue(value='FR')])

        self.assertEqual(self.resolve('P246', 'Q743'),
                         [StringValue(value='W')])

        self.assertEqual(self.resolve('P17', 'Q83259'), [ItemValue(id='Q142')])

        # With dot
        self.assertEqual(self.resolve('./P2427', 'Q34433'),
                         [IdentifierValue(value='grid.4991.5')])
        self.assertEqual(self.resolve('P2427/.', 'Q34433'),
                         [IdentifierValue(value='grid.4991.5')])

        # With disjunction
        self.assertSetEqual(
            set(self.resolve(
                'P17',  # country
                'Q1011981',  # google china
            )),
            {ItemValue(id='Q148')})  # china
        self.assertSetEqual(
            set(
                self.resolve(
                    'P749/P17',  # parent org. / country
                    'Q1011981',  # google china
                )),
            {ItemValue(id='Q30')})  # USA
        self.assertSetEqual(
            set(
                self.resolve(
                    'P17|(P749/P17)',  # brackets not actually needed
                    'Q1011981')),
            {ItemValue(id='Q148'), ItemValue(id='Q30')})  # USA + China

        # With term
        self.assertEqual(self.resolve('P17/Lfr', 'Q83259'),
                         [IdentifierValue(value='France')])
Ejemplo n.º 2
0
    def test_resolve_property_path(self):
        self.assertEqual(self.resolve('P297', 'Q142'),
                         [IdentifierValue(value='FR')])

        self.assertTrue(
            IdentifierValue(value='FR') in self.resolve('Afr', 'Q142'))

        self.assertEqual(self.resolve('P17/P297', 'Q83259'),
                         [IdentifierValue(value='FR')])

        self.assertEqual(self.resolve('P246', 'Q743'),
                         [StringValue(value='W')])

        self.assertEqual(self.resolve('P1449', 'Q1249148'), [
            MonolingualValue(text='Dick', language='en'),
            MonolingualValue(text='Rich', language='en')
        ])

        self.assertEqual(self.resolve('P17', 'Q83259'), [ItemValue(id='Q142')])

        self.assertEqual(self.resolve('P17/qid', 'Q83259'),
                         [IdentifierValue(id='Q142')])

        self.assertEqual(self.resolve('qid', 'Q142'),
                         [IdentifierValue(id='Q142')])

        # Qualifier
        self.assertEqual(self.resolve('P4424_P518', 'Q42023001'),
                         [ItemValue(id='Q2106255')])

        # With dot
        self.assertEqual(self.resolve('./P2427', 'Q34433'),
                         [IdentifierValue(value='grid.4991.5')])
        self.assertEqual(self.resolve('P2427/.', 'Q34433'),
                         [IdentifierValue(value='grid.4991.5')])

        # With disjunction
        self.assertSetEqual(
            set(self.resolve(
                'P17',  # country
                'Q1011981',  # google china
            )),
            {ItemValue(id='Q148')})  # china
        self.assertSetEqual(
            set(
                self.resolve(
                    'P749/P17',  # parent org. / country
                    'Q1011981',  # google china
                )),
            {ItemValue(id='Q30')})  # USA
        self.assertSetEqual(
            set(
                self.resolve(
                    'P17|(P749/P17)',  # brackets not actually needed
                    'Q1011981')),
            {ItemValue(id='Q148'), ItemValue(id='Q30')})  # USA + China

        # With term
        self.assertEqual(self.resolve('P17/Lfr', 'Q83259'),
                         [IdentifierValue(value='France')])
async def test_resolve_property_path(resolve):
    assert (await resolve('P297', 'Q142') == [IdentifierValue(value='FR')])

    assert (IdentifierValue(value='FR') in await resolve('Afr', 'Q142'))

    assert (await resolve('P17/P297',
                          'Q83259') == [IdentifierValue(value='FR')])

    assert (await resolve('P246', 'Q743') == [StringValue(value='W')])

    assert (await resolve('P1449', 'Q1249148') == [
        MonolingualValue(text='Dick', language='en'),
        MonolingualValue(text='Rich', language='en'),
        MonolingualValue(text='Rik', language='en'),
        MonolingualValue(text='Richey', language='en'),
        MonolingualValue(text='Rick', language='en'),
        MonolingualValue(text='Ritchie', language='en')
    ])

    assert (await resolve('P17', 'Q83259') == [ItemValue(id='Q142')])

    assert (await resolve('P17/qid',
                          'Q83259') == [IdentifierValue(value='Q142')])

    assert (await resolve('qid', 'Q142') == [IdentifierValue(value='Q142')])

    # Qualifier
    assert (await resolve('P4424_P518',
                          'Q42023001') == [ItemValue(id='Q2106255')])

    # With dot
    assert (await resolve('./P2427',
                          'Q34433') == [IdentifierValue(value='grid.4991.5')])
    assert (await resolve('P2427/.',
                          'Q34433') == [IdentifierValue(value='grid.4991.5')])

    # With disjunction
    assert (set(await resolve(
        'P17',  # country
        'Q30273752',  # microsoft france
    )) == {ItemValue(id='Q142')})  # france
    assert (set(await resolve(
        'P749/P17',  # parent org. / country
        'Q30273752',  # microsoft france
    )) == {ItemValue(id='Q30')})  # USA
    assert (set(await resolve(
        'P17|(P749/P17)',  # brackets not actually needed
        'Q30273752')) == {ItemValue(id='Q142'),
                          ItemValue(id='Q30')})  # USA + France

    # With term
    assert (await resolve('P17/Lfr',
                          'Q83259') == [IdentifierValue(value='France')])

    # With sitelink
    assert (await resolve('P17/Sfrwiki',
                          'Q83259') == [IdentifierValue(value='France')])
 def resolve(self, exp, qid):
     path = self.f.parse(exp)
     return list(path.step(ItemValue(id=qid)))
 async def _resolve(exp, qid):
     path = property_factory.parse(exp)
     return list(await path.step(ItemValue(id=qid)))