Browse the values ​​of a variable with Flask and Owlready

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

Browse the values ​​of a variable with Flask and Owlready

Barnabe
hi,
I would like to iterate through the values ​​of a variable which is supposed to contain the ids of a class.
Here are the steps :

from owlready2 import *
onto_path.append("Ontologie_v1")
onto = get_ontology("http://www.idexationsemantique.bf/index_semantique.owl")
onto.load()
onto.Personne.iri   gives out  "http://www.idexationsemantique.bf#Personne"
pers = onto.Personne()      #Gives an identifiant of name personne1
pers = onto.Personne()      #Gives an identifiant of name personne2

for s in pers2:
...     print(s)            

Gives out "TypeError: 'Personne' object is not iterable"


My final goal is to iterate through all the values ​​of data properties like in relational database and display them on my page

value = onto.personne1.possede = ["Loc"]
value = onto.personne2.possede = ["Mixte"]

Display all data properties through the variable "values" on my website page.

Any help will be welcome.
Thank you
Reply | Threaded
Open this post in threaded view
|

Re: Browse the values ​​of a variable with Flask and Owlready

Jiba
Administrator
Hi,

You can iterate through the values of the data property as follows:

for value in onto.personne2.possede:
      print(value)

or:

for value in pers2.possede:
      print(value)

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Browse the values ​​of a variable with Flask and Owlready

Barnabe
Hi,
I tried your answer but get the last value saved in the variable.
The other values ​​seem to be overwritten, but I want to recover all the variables according to their identifiers.
Reply | Threaded
Open this post in threaded view
|

Re: Browse the values ​​of a variable with Flask and Owlready

Jiba
Administrator
Hi,

If you do:

    onto.personne1.possede = ["Loc"]

then you erase the previous value(s) and put "Loc" as the unique value.

If you want to add a value, keeping the eventual previous values, you should do:

    onto.personne1.possede.append("Loc")

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Browse the values ​​of a variable with Flask and Owlready

Barnabe
Hi,
indeed, I receive all the values.
But when I want to save data for the first time, I get an error like "obj.namespace.ontology._add_obj_triple_spo (obj.storid, self._Prop.storid, added.storid)
AttributeError: 'str' object has no attribute 'storid'
", and if I recall the command, no error but the value is duplicated.
Reply | Threaded
Open this post in threaded view
|

Re: Browse the values ​​of a variable with Flask and Owlready

Jiba
Administrator
Hi,

Is 'possede' a data property or an object property? If it is an object property, you must provide individuals as values, not string.

Jiba