pip install politylink
If you are using politylink.nlp.keyphrase , do the following with an additional procedure:
pip install git+https://github.com/boudinfl/pke.git
python -m nltk.downloader stopwords
A GraphQLClient is provided to access PolityLink's GraphQL endpoints.
from politylink.graphql.client import GraphQLClient
client = GraphQLClient()
You can use the exec method to execute any GraphQL query.
query = """
query {
Bill(filter: {submittedDate: {year: 2020, month: 1, day: 20}}) {
name
}
}
"""
client.exec(query)
The names of the three bills submitted on January 20, 2020 should be obtained in JSON format.
{'data': {'Bill': [{'name': '特定複合観光施設区域の整備の推進に関する法律及び特定複合観光施設区域整備法を廃止する法律案'},
{'name': '地方交付税法及び特別会計に関する法律の一部を改正する法律案'},
{'name': '平成三十年度歳入歳出の決算上の剰余金の処理の特例に関する法律案'}]}}
You can also use get_all_* method to retrieve the return value as an instance of a Python class rather than as a JSON. For example, get_all_bills allows you to retrieve bills as Bill instances.
bills = client.get_all_bills(fields=['id', 'name'])
first_bill = bills[0]
print(f'{len(bills)}件の法律案を取得しました')
print(f'最初の法律案は「{first_bill.name}」({first_bill.id})です')
You should get the id and name of all bills. The return value is a Bill instance, so you can access each field using dots.
207件の法律案を取得しました
最初の法律案は「地方交付税法及び特別会計に関する法律の一部を改正する法律案」(Bill:s1QZfjoCPyfdXXbrplP3-A)です
You can also specify a condition by passing filter_ as an argument. See the advanced version for more details.
GraphQLClient is a wrapper class for sgqlc, and queries can also be assembled in code. For example, if you assemble the query for the first exec example, it would look like this:
from politylink.graphql.schema import Query, _BillFilter, _Neo4jDateTimeInput
from sgqlc.operation import Operation
op = Operation(Query)
filter_ = _BillFilter(None)
filter_.submitted_date = _Neo4jDateTimeInput(year=2020, month=1, day=20)
bills = op.bill(filter=filter_)
bills.name()
client.exec(op)
The assembled Operation is automatically converted to a string, so it can be passed directly to exec .
You can also pass the filter_ created above as an argument to get_all_* method.
client.get_all_bills(fields=['name'], filter_=filter_)
The first three bills were obtained as Bill instances.
[Bill(name='地方交付税法及び特別会計に関する法律の一部を改正する法律案'),
Bill(name='平成三十年度歳入歳出の決算上の剰余金の処理の特例に関する法律案'),
Bill(name='特定複合観光施設区域の整備の推進に関する法律及び特定複合観光施設区域整備法を廃止する法律案')]