[Developers] looking for people

Tom Morris tfmorris at gmail.com
Mon Mar 30 03:47:24 UTC 2009


Oops, looks like my reply crossed with Will's.  I've got a growing
collection of Python utilities for doing this kind of stuff that I'll
try to get published somewhere.

Here's a method that will build the kind of query that you probably
want to use.  It takes a list of names generated separately from
permutations of first name, middle name, middle initial, family name,
generational suffix (Sr, Jr, III, etc).  The key little trick (which I
didn't invent) is the way both name and alias are searched for
matches.

    def name_query(self, name):
        '''
        Construct a query to look up a person in Freebase with the given name
        (or list of name alternatives)
        and return all the info we're interested in.  Most things are only used
        for scoring, rather than constraining the lookup, so they're optional.
        '''
        sub_query = [{'lang' : '/lang/en',
                        'link|=' : ['/type/object/name',
                                    '/common/topic/alias'],
                        'type' : '/type/text'
                        }]

        if '*' in name:
            sub_query[0]['value~='] = name
        elif isinstance(name,list):
            sub_query[0]['value|='] = name
        else:
            sub_query[0]['value'] = name

        query = {'/type/reflect/any_value' : sub_query,
                  't1:type' : '/people/person',
                  't2:type' : '/common/topic',
                  't3:type' : {'name' : '/people/deceased_person',
                               'optional': True},
                  'id' : None
                  }
        return [self.decorate_query(query)]


More information about the Developers mailing list