ProjetPP / PPP-QuestionParsing-Grammatical

Question Parsing module for the PPP using a grammatical approch
GNU Affero General Public License v3.0
33 stars 11 forks source link

Datamodel Python - Change a predicate #115

Closed yhamoudi closed 9 years ago

yhamoudi commented 9 years ago

I try to change the predicate of a Triple node n by doing: n.predicate = .... However i obtain the error AttributeError: 'Triple' object has no attribute 'predicate'

You can reproduce the error using the file demo8.py (in demo folder) and the question Who am i

yhamoudi commented 9 years ago

It's really strange. I can access n.predicate (print(n.predicate) works) but not change it

yhamoudi commented 9 years ago

So how can i do? I need to rebuild all the normal form?

progval commented 9 years ago

Yes.

Mutable tree generally are not a good idea, unless you want to spend a lot of time debugging weird bugs.

yhamoudi commented 9 years ago

ok.

Let's imagine i have a node n whose type belongs to (List,Intersection,Union,And,Or,Last,First,Exists). I would like to build a normal form identical to n except that n.list contains one new element a.

I could split this task:

if isinstance(n,List):
  return List(n.list+[a])
elif isinstance(n,Intersection):
  return Intersection(n.list+[a])
...

Is there a way to do this quicker?

yhamoudi commented 9 years ago

Finally, i've done:

if isinstance(n,(List,Intersection,Union,And,Or,Last,First,Exists)):
    return type(n)(n.list+[a])