question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get names of individuals

See original GitHub issue

I would like to get the name of all of the instances of a given class, but without the URI prefix. I think this is more of an RDFLib specific issue dealing with URIRef objects, but maybe there’s a solution inside ontospy that I haven’t found yet

import ontospy
test_ontology_url = "http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine"
ont = ontospy.Ontospy(test_ontology_url)
for clz in o.classes:
    print(clz)
    for instance in clz.instances():
        print(instance)
        print(dir(instance))

Output:

<Class *http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#AlsatianWine*>
<Class *http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#AmericanWine*>
<Class *http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#Anjou*>
http://www.w3.org/TR/2003/PR-owl-guide-20031209/wine#RoseDAnjou
['__add__', '__class__', '__contains__', '__delattr__', '__dir__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__getitem__', '__getnewargs__', '__gt__', '__hash__', '__init__', '__invert__', '__iter__', '__le__', '__len__', '__lt__', '__mod__', '__module__', '__mul__', '__ne__', '__neg__', '__new__', '__or__', '__radd__', '__reduce__', '__reduce_ex__', '__repr__', '__rmod__', '__rmul__', '__setattr__', '__sizeof__', '__slots__', '__str__', '__subclasshook__', '__truediv__', 'capitalize', 'casefold', 'center', 'count', 'de_skolemize', 'defrag', 'encode', 'endswith', 'eq', 'expandtabs', 'find', 'format', 'format_map', 'index', 'isalnum', 'isalpha', 'isdecimal', 'isdigit', 'isidentifier', 'islower', 'isnumeric', 'isprintable', 'isspace', 'istitle', 'isupper', 'join', 'ljust', 'lower', 'lstrip', 'maketrans', 'md5_term_hash', 'n3', 'neq', 'partition', 'replace', 'rfind', 'rindex', 'rjust', 'rpartition', 'rsplit', 'rstrip', 'split', 'splitlines', 'startswith', 'strip', 'swapcase', 'title', 'toPython', 'translate', 'upper', 'zfill']

...

None of the functions listed with dir return what I want (I iterated through all them and ran them) What I’d like is simply a way to retrieve:

RoseDAnjou

And make it a bit more general than splitting on the # character, since not all ontologies have to use a # to differentiate the base IRI and the members, correct? Thanks so much for the help!

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
lambdamusiccommented, Apr 27, 2017

Ok I’ll try to add that with the next release.

2reactions
lambdamusiccommented, Mar 21, 2018

Added with v1.8.8. Sorry it’s taken so long! You can now do this:

for instance in class.instances:
    print instance.uri, instance.qname

Note: instances are extracted on demand (once the method is called) so to avoid unnecessary calculations due to metaclasses and the same object being at the same time an instance and a class.

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to get database of all people's names (or at least English ...
Alternatively, you can get a list of person names from the Web (there are plenty), and use the Aho-Corasick string searching algorithm to ......
Read more >
List of people by name - Wikiquote
Every person for whom there is a quotation page should be listed here, ordered by last name unless they don't have one.
Read more >
11 memory hacks to remember the names of everyone you meet
3. Repeat the name of the person you just met. ... One way to help you remember a person's name is to find...
Read more >
How to remember people's names | Zapier
Remembering names is hard. Here are 5 steps for remembering names to help you make stronger connections.
Read more >
SQL Query to Find the Name of a Person Whose Name Starts ...
Here, we are going to see how to find the name of a person whose name starts with a specified letter in SQL....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found