ORKG Classes
Resources in the ORKG are typed to one or more of the ORKG’s classes, in order to be able to access this information or manipulate it (i.e., add, edit, delete) a classes component is added to the ORKG class to encapsulate the actions.
Having defined our entry point to the ORKG instance
from orkg import ORKG # import base class from package
orkg = ORKG(host="<host-address-is-here>", creds=('email-address', 'password')) # create the connector to the ORKG
We can access the classes manager directly to do the following:
Getting class by ID
You can get certain class given that you know their ID value
### Fetch class by id
# id: the class id
orkg.classes.by_id(id='C5')
>>> (Success)
{
"id":"C5",
"label":"MeasureProperty",
"uri":"None",
"created_at":"2020-05-11T14:52:34.316361+02:00",
"created_by":"00000000-0000-0000-0000-000000000000",
"_class":"class"
}
Getting classes by lookup
You can lookup a class by it’s label. You can set a parameter to specify an exact match or a loose one.
### Fetch a list of predicates
# All parameters are optional
# q: to search for a label containing
# exact: to condition the search to as is
orkg.classes.get_all(q='Property', exact=False)
>>> (Success)
[
{
"id":"C5",
"label":"MeasureProperty",
"uri":"None",
"created_at":"2020-05-11T14:52:34.316361+02:00",
"created_by":"00000000-0000-0000-0000-000000000000",
"_class":"class"
},
...
]
Adding a new class
The ORKG package can be used to create new classes in the ORKG instance you are connected to.
Note: if you have you credentials entered in the ORKG instance creation all newly added predicates will be credited to your user.
### Add a class
# id: the id of the class (optional)
# label: the label of the class
# uri: the external uri that is equivalent to this class from an ontology or a taxonomy (optional)
orkg.classes.add(id='Custom_ID', label='new class', uri='http://external-vocab.com')
>>> (Success)
{
"id":"Custom_ID",
"label":"new class",
"uri":"http://external-vocab.com",
"created_at":"2020-05-11T14:52:34.316361+02:00",
"created_by":"00000000-0000-0000-0000-000000000000",
"_class":"class"
}
Updating an existing class
You can also update an existing class in the ORKG other than creating a new one. (*Use carefully*)
### Updates a class
# id (mandatory): the id of the class to change
# label (mandatory): the new label of the class
orkg.classes.update(id='Custom_ID', label='Coco')
>>> (Success)
{
"id":"Custom_ID",
"label":"Coco",
"uri":"http://external-vocab.com",
"created_at":"2020-05-11T14:52:34.316361+02:00",
"created_by":"00000000-0000-0000-0000-000000000000",
"_class":"class"
}
Check if a class exists
For your code to run smoothly you can check for the existence of classes before you update them for example. You can make sure that you code doesn’t run into unexpected results.
### Checks if class exists
# id: the id of the class
# returns a bool
orkg.classes.exists(id='C1')
>>> True