Giter Club home page Giter Club logo

pyneql's Introduction

PyNeQL

A module for searching Named Entity on SPARQL endpoints

Python version Build Status Coverage Status Documentation Status
Dev Status


Linked Data is the global database of the World Wide Web. One can query those linked databases by sending SPARQL queries to different endpoints.

SPARQL vocabularies are huge and it is sometimes tedious to find how to ask for simple things as Named Entities.

This module aim to provide a very simple way to query named entities by their name, and retrieve a maximum of information from different SPARQL endpoints.

You can read the docs here.

Table of Contents


Quick Start

Installation instructions

Just type the pip command in your env:

pip install pyneql

Or you can install PyNeQL by cloning the project to your local directory

git clone https://github.com/Valerie-Hanoka/PyNeQL.git

run setup.py

python setup.py install

I plan to submit it to PyPI soon.

Usage

Finding a Person

Looking for Bell Hooks in the Bibliothèque Nationale de France, DBPedia, Wikidata and the French DBPedia:

# -*- coding: utf-8 -*-

from pyneql.ontology.person import Person
from pyneql.utils.endpoints import Endpoint

# Looking for Bell Hooks
endpoints = [Endpoint.dbpedia_fr, Endpoint.dbpedia, Endpoint.wikidata, Endpoint.bnf]
bell_hooks = Person(first_name="bell", last_name="hooks")
bell_hooks.add_query_endpoints(endpoints)
bell_hooks.query()

At the moment, the result is as follow:

# The result of the query contains 15 pieces of information about Bell Hooks.
pprint.pprint(bell_hooks.attributes)
# {
#     u'skos:exactMatch': u'http://data.bnf.fr/ark:/12148/cb12519986q#foaf:Person',
#     u'rdf:type': u'foaf:Person',
#     u'foaf:depiction': set([u'http://commons.wikimedia.org/wiki/Special:FilePath/Bellhooks.jpg?width=300'
#                            ,
#                            u'https://upload.wikimedia.org/wikipedia/commons/7/7b/Bellhooks.jpg'
#                            ,
#                            u'http://commons.wikimedia.org/wiki/Special:FilePath/Bellhooks.jpg'
#                            ]),
#     u'foaf:name': u'bell hooks',
#     u'rdagroup2elements:biographicalInformation': u'Essayiste et enseignante. - Militante f\xe9minisme et contre la s\xe9gragation raciale. - Fondatrice, en 2014, du bell hooks Institute, Berea College (Ky., \xc9tats-Unis). - Pseudonyme de Gloria Jean Watkins',
#     u'owl:sameAs': set([u'http://data.bnf.fr/ark:/12148/cb12519986q#foaf:Person'
#                        , u'dbpedia_fr:Bell_hooks',
#                        u'http://viaf.org/viaf/79115934',
#                        u'http://data.bnf.fr/ark:/12148/cb12519986q#about'
#                        ]),
#     u'bnf_onto:firstYear': u'1952',
#     u'foaf:gender': u'female',
#     u'rdagroup2elements:countryAssociatedWithThePerson': u'http://id.loc.gov/vocabulary/countries/xxu',
#     u'rdagroup2elements:fieldOfActivityOfThePerson': set([u'http://dewey.info/class/300/'
#             , u'Sciences sociales. Sociologie']),
#     u'rdagroup2elements:languageOfThePerson': u'http://id.loc.gov/vocabulary/iso639-2/eng',
#     u'foaf:familyName': u'hooks',
#     u'foaf:givenName': u'bell',
#     u'validated': 1,
#     u'foaf:page': u'http://data.bnf.fr/12519986/bell_hooks/',
#     }

# It is possible to find further information about Bell Hooks
bell_hooks.find_more_about()

# person.find_more_about() gives 208 more attribute-keys values about her:
len(bell_hooks.attributes)
# 223
Language of the query

It is also possible to specify the language of the query, and retrieve some information about the person. In this Snippet, we are looking for Vivian Qu by her Chinese name:

from pyneql.ontology.person import Person
from pyneql.utils.endpoints import Endpoint
from pyneql.utils.enum import LanguagesIso6391 as Lang


endpoints = [Endpoint.dbpedia_fr, Endpoint.dbpedia, Endpoint.wikidata, Endpoint.bnf]
vivian_qu = Person(full_name=u'文晏', query_language=Lang.Chinese)
vivian_qu.add_query_endpoints(endpoints)
vivian_qu.query()

# If is possible to access some important information via dedicated methods

vivian_qu.get_names()
# {u'foaf:givenName': u'Vivian',
#  u'foaf:name': [u'\u6587\u664f', u'Vivian Qu'],
#  u'foaf:surname': u'Qu',
#  u'rdfs:label': [u'\u30f4\u30a3\u30f4\u30a3\u30a2\u30f3\u30fb\u30c1\u30e5\u30a4',
#                  u'\u0641\u064a\u0641\u064a\u0627\u0646 \u062a\u0634\u0648',
#                  u'Vivian Qu',
#                  u'\u6587\u664f'],
#  u'wdt:given_name_(P735)': u'wd:Q650494'}


vivian_qu.get_birth_info()
# {'date': datetime.datetime(1950, 1, 1, 0, 0, tzinfo=tzutc()),
#  'place': u'Beijing, China'}

Finding Anything

I plan to develop other classes that will allow safe query of named entites of type Location, Books, TimePeriods,...

The class Thing will only be used as a common parent for all other named entities classes. As it is not safe to use, I describe it there just for fun.

Looking for አዲስ አበባ in Amharic, on DBPedia:

from pyneql.ontology.thing import Thing
from pyneql.utils.endpoints import Endpoint
from pyneql.utils.enum import LanguagesIso6391 as Lang

addis_abeba = Thing(label=u'አዲስ አበባ', query_language=Lang.Amharic)
addis_abeba.add_query_endpoint(Endpoint.dbpedia)
addis_abeba.query(strict_mode=True)

# It is possible to access information via keyword search
addis_abeba.get_attributes_with_keyword('abel')
# {u'rdfs:label': set([u'Adas Ababa',
#                      u'Addis Ababa',
#                      u'Addis Abeba',
#                      u'Addis-Abeb',
#                      u'Addis-Abeba',
#                      u'Addisz-Abeba',
#                      u'Adis Ababa',
#                      u'Adis Abeba',
#                      u'Adis-Abeba',
#                      u'Adis-Abebo',
#                      u'Adisabeba',
#                      u'Ad\xeds Abeba',
#                      u'Neanthopolis',
#                      u'\u018fddis-\u018fb\u0259b\u0259',
#                      u'\u0391\u03bd\u03c4\u03af\u03c2 \u0391\u03bc\u03c0\u03ad\u03bc\u03c0\u03b1',
#                      u'\u0410\u0434\u0434\u0438\u0441-\u0410\u0431\u0435\u0431\xe6',
#                      u'\u0410\u0434\u0434\u0438\u0441-\u0410\u0431\u0435\u0431\u0430',
#                      u'\u0410\u0434\u0438\u0441 \u0410\u0431\u0435\u0431\u0430',
#                      u'\u0410\u0434\u044b\u0441-\u0410\u0431\u044d\u0431\u0430',
#                      u'\u0413\u043e\u0440\u0430\u0434 \u0410\u0434\u044b\u0441-\u0410\u0431\u0435\u0431\u0430',
#                      u'\u0531\u0564\u056b\u057d \u0531\u0562\u0565\u0562\u0561',
#                      u'\u05d0\u05d3\u05d9\u05e1 \u05d0\u05d1\u05d0\u05d1\u05d0',
#                      u'\u05d0\u05d3\u05d9\u05e1 \u05d0\u05d1\u05d1\u05d4',
#                      u'\u0622\u062f\u06cc\u0633 \u0622\u0628\u0627\u0628\u0627',
#                      u'\u0623\u062f\u064a\u0633 \u0623\u0628\u0627\u0628\u0627',
#                      u'\u0626\u0627\u062f\u06cc\u0633 \u0626\u0627\u0628\u0627\u0628\u0627',
#                      u'\u0627\u062f\u064a\u0633 \u0627\u0628\u0627\u0628\u0627',
#                      u'\u0627\u062f\u06cc\u0633 \u0627\u0628\u0627\u0628\u0627',
#                      u'\u0905\u0926\u093f\u0938 \u0905\u092c\u093e\u092c\u093e',
#                      u'\u0905\u0926\u0940\u0938 \u0905\u092c\u093e\u092c\u093e',
#                      u'\u0986\u09a6\u09cd\u09a6\u09bf\u09b8 \u0986\u09ac\u09be\u09ac\u09be',
#                      u'\u0a06\u0a26\u0a3f\u0a38 \u0a06\u0a2c\u0a2c\u0a3e',
#                      u'\u0b85\u0b9f\u0bbf\u0bb8\u0bcd \u0b85\u0baa\u0bbe\u0baa\u0bbe',
#                      u'\u0c05\u0c26\u0c4d\u0c26\u0c3f\u0c38\u0c4d \u0c05\u0c2c\u0c3e\u0c2c\u0c3e',
#                      u'\u0c85\u0ca1\u0cbf\u0cb8\u0ccd \u0c85\u0cac\u0cbe\u0cac',
#                      u'\u0d05\u0d21\u0d3f\u0d38\u0d4d \u0d05\u0d2c\u0d46\u0d2c',
#                      u'\u0e41\u0e2d\u0e14\u0e14\u0e34\u0e2a\u0e2d\u0e32\u0e1a\u0e32\u0e1a\u0e32',
#                      u'\u0f68\u0f0b\u0f4c\u0f72\u0f0b\u0f66\u0f72\u0f0b\u0f68\u0f0b\u0f56\u0f0b\u0f56\u0f0d',
#                      u'\u1021\u102c\u1012\u1005\u103a \u1021\u102c\u1018\u102c\u1018\u102c\u1019\u103c\u102d\u102f\u1037',
#                      u'\u10d0\u10d3\u10d8\u10e1-\u10d0\u10d1\u10d4\u10d1\u10d0',
#                      u'\u12a0\u12f2\u1235 \u12a0\u1260\u1263',
#                      u'\u30a2\u30c7\u30a3\u30b9\u30a2\u30d9\u30d0',
#                      u'\u4e9a\u7684\u65af\u4e9a\u8d1d\u5df4',
#                      u'\u963f\u8fea\u65af\u963f\u8c9d\u5df4',
#                      u'\uc544\ub514\uc2a4\uc544\ubc14\ubc14']),
#  u'skos:altLabel': set([u'Addis',
#                         u'Finifinee',
#                         u'\u0100dd\u012bs \u0100beb\u0101'])

pyneql's People

Contributors

valerie-hanoka avatar

Stargazers

Felipe Macias avatar  avatar jeromecc avatar  avatar Luc Boruta avatar

Watchers

James Cloos avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.