How to work with owlready correctly?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

How to work with owlready correctly?

Diego
Hello! I try to understand how to work with owlready using https://pypi.python.org/pypi/Owlready
The next text is given by that link:

Load an ontology from a local repository, or from Internet:
>>> from owlready import *
>>> onto_path.append("/path/to/your/local/ontology/repository")
>>> onto = get_ontology("http://www.lesfleursdunormal.fr/static/_downloads/pizza_onto.owl")
>>> onto.load()

Ok. In "Python 2.7.14 Shell"  i'm typing:
>>> from owlready import *
and then i get error message:

Traceback (most recent call last):
  File "<pyshell#0>", line 1, in <module>
    from owlready import *
  File "C:\Python27\lib\site-packages\owlready\__init__.py", line 154
    def __init__(self, *Entities, ontology = None):
                                         ^
SyntaxError: invalid syntax

Help me, please! What should I do for correct working with owlready?
Reply | Threaded
Open this post in threaded view
|

Re: How to work with owlready correctly?

Jiba
Administrator
Hello,

You need Python 3.x (probably 3.3 at least) for Owlready. Python 2.7 is not supported.

Best regards,
Jean-Baptiste Lamy
MCF, LIMICS, Université Paris 13
Reply | Threaded
Open this post in threaded view
|

Re: How to work with owlready correctly?

Diego
Thanks! I really needed Python ver. 3.x. I installed required version. But I still have several problems. Can you help me to download ontology from OWL-file? I don't understand how do it correctly. I used information from http://pythonhosted.org/Owlready/onto.html#loading-an-ontology-from-owl
but I didn't download ontology from file. That information told me about downloading by IRI. Concerning downloading from OWL-file, infromation is not enough.
I will be grateful if you would tell me what commands I need to type for ontology downloading from OWL-file on my hard drive.
Reply | Threaded
Open this post in threaded view
|

Re: How to work with owlready correctly?

Chris
In reply to this post by Jiba
Hi Jean-Baptiste,

Could you enable the support of Python 2.7 (at least 2.7.10+) with Owlready2?

This will be great and appreciate. In fact, Python 2.7 being actively used in the open source community, such a support will increase the adoption of Owlready (one of the few python package for working with Ontologies).

Regards,
Chris
Reply | Threaded
Open this post in threaded view
|

Re: How to work with owlready correctly?

Jiba
Administrator
Hello,

Supporting Python 2.7 would be interesting, however, it it would also complicate the maintenance of Owlready2. Since I use only Python 3 (I migrated all my Python 2 programs a few years ago), I cannot maintain a Python 2 library efficiently.

Kind regards,
Jean-Baptiste Lamy
MCF, LIMICS, Université Paris 13
Reply | Threaded
Open this post in threaded view
|

Re: How to work with owlready correctly?

Jiba
Administrator
In reply to this post by Diego
The doc you are using is for Owlready 1; the link for Owlready 2 is :

        http://owlready2.readthedocs.io/en/latest/

The easiest way to open an ontology from a file is :

>>> onto = get_ontology("file:///home/jiba/onto/pizza_onto.owl").load()
Reply | Threaded
Open this post in threaded view
|

Re: How to work with owlready correctly?

Diego
Ok. I have question. For example.
I am typing:

onto = get_ontology("C:\Python33\Railway.owl").load()

and I receive:

* Owlready * Creating new ontology C:\Python33\Railway <C:\Python33\Railway.owl>.
Traceback (most recent call last):
  File "<pyshell#3>", line 1, in <module>
    onto = get_ontology("C:\Python33\Railway.owl").load()
  File "C:\Python33\lib\site-packages\owlready\__init__.py", line 275, in load
    f = fileobj or _open_onto_file(self.base_iri, self.name, "r", only_local)
  File "C:\Python33\lib\site-packages\owlready\__init__.py", line 200, in _open_onto_file
    if (mode == "r") and not only_local: return urllib.request.urlopen(base_iri)
  File "C:\Python33\lib\urllib\request.py", line 156, in urlopen
    return opener.open(url, data, timeout)
  File "C:\Python33\lib\urllib\request.py", line 469, in open
    response = self._open(req, data)
  File "C:\Python33\lib\urllib\request.py", line 492, in _open
    'unknown_open', req)
  File "C:\Python33\lib\urllib\request.py", line 447, in _call_chain
    result = func(*args)
  File "C:\Python33\lib\urllib\request.py", line 1310, in unknown_open
    raise URLError('unknown url type: %s' % type)
urllib.error.URLError: <urlopen error unknown url type: c>

What am I doing wrong?
Reply | Threaded
Open this post in threaded view
|

Re: How to work with owlready correctly?

Jiba
Administrator
get_ontology expects an URL, so you need to add "file://" at the beginning of your filename :

onto = get_ontology("file://C:\Python33\Railway.owl").load()