From 0f99414d98c6a80c68ce9c6f4c667db1dba02a27 Mon Sep 17 00:00:00 2001 From: Koichi Yasuoka Date: Sun, 15 Sep 2019 07:43:28 +0900 Subject: [PATCH] speed up --- conllusvg/UDPipe2UD.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/conllusvg/UDPipe2UD.py b/conllusvg/UDPipe2UD.py index ffb38711fe2..51da3b4fa15 100755 --- a/conllusvg/UDPipe2UD.py +++ b/conllusvg/UDPipe2UD.py @@ -1,5 +1,5 @@ #! /usr/bin/python -i -# "UDPipe2UD.py" by Koichi Yasuoka, July 3, 2019. +# "UDPipe2UD.py" by Koichi Yasuoka, September 15, 2019. class UDPipeEntry(object): def __init__(self,result): @@ -9,10 +9,10 @@ class UDPipeEntry(object): w=UDPipeEntry(r) if w.id>0: t.append(w) - for i,w in enumerate(t): - w.head=w if w._head==0 else t[i+w._head-w.id] - w._parent=self self._tokens=t + for w in t: + w._parent=self + w.head=w._head self._result=result else: w=result.split("\t") @@ -24,11 +24,11 @@ class UDPipeEntry(object): self._result="" def __setattr__(self,name,value): v=value + if name=="head": + t=self._parent._tokens + i=t.index(self) + v=self if v==0 else t[i+v-self.id] if hasattr(self,name): - if name=="head": - t=self._parent._tokens - i=t.index(self) - v=self if v==0 else t[i+v-self.id] if getattr(self,name)!=v: super(UDPipeEntry,self._parent).__setattr__("_result","") if name=="id": -- GitLab