Skip to main content
etiquetas editadas
Enlace
Pikoh
  • 17.5k
  • 9
  • 41
  • 56
se añadieron 167 caracteres en el cuerpo
Origen Enlace
class WordTree:
    def __init__(self, array, parent = None):
        #print("son :",array[0][i])
        self.parent = []
        self.children = [] # if parenthesis then it has son after "," analyse : include all elements until the next parenthesi
        self.data = array
        #print(array[0])
        for son in array[0]:
            print(type(son),son)
            if type(son) is Tree:
                print("sub tree creation")
                self.children.append(son.label())
                print("son:",son)
                t = WordTree(son,son.label()) # should I verify if parent is empty ?
            elif type(son) is str:
 print("end of sub tree creation")
            print("sonelif creation"type(son)
  is str:
              self.parent = parentprint("son creation")
                self.children.append(son)
            else:
                print("issue?")
                break # prolbem ?
>>> t = WordTree(treeQuestion, treeQuestion[0].label())
<class 'str'> When_WRB_advmod
son creation
<class 'str'> did_VBD_aux
son creation
<class 'str'> Beyonce_NNP_nsubj
son creation
<class 'nltk.tree.Tree'> (becoming_VBG_xcomp popular_JJ_acomp)
sub tree creation
son: (becoming_VBG_xcomp popular_JJ_acomp)
<class 'str'> p
son creation
<class 'str'> o
son creation
<class 'str'> p
class WordTree:
    def __init__(self, array, parent = None):
        #print("son :",array[0][i])
        self.parent = []
        self.children = [] # if parenthesis then it has son after "," analyse : include all elements until the next parenthesi
        self.data = array
        #print(array[0])
        for son in array[0]:
            print(type(son),son)
            if type(son) is Tree:
                print("sub tree creation")
                t = WordTree(son) # should I verify if parent is empty ?
            elif type(son) is str:
                print("son creation")
                 self.parent = parent
                self.children.append(son)
            else:
                print("issue?")
                break # prolbem ?
>>> t = WordTree(treeQuestion, treeQuestion[0].label())
<class 'str'> When_WRB_advmod
son creation
<class 'str'> did_VBD_aux
son creation
<class 'str'> Beyonce_NNP_nsubj
son creation
<class 'nltk.tree.Tree'> (becoming_VBG_xcomp popular_JJ_acomp)
sub tree creation
<class 'str'> p
son creation
<class 'str'> o
son creation
<class 'str'> p
class WordTree:
    def __init__(self, array, parent = None):
        #print("son :",array[0][i])
        self.parent = []
        self.children = [] # if parenthesis then it has son after "," analyse : include all elements until the next parenthesi
        self.data = array
        #print(array[0])
        for son in array[0]:
            print(type(son),son)
            if type(son) is Tree:
                print("sub tree creation")
                self.children.append(son.label())
                print("son:",son)
                t = WordTree(son,son.label()) # should I verify if parent is empty ?
                print("end of sub tree creation")
            elif type(son) is str:
                print("son creation")
                self.children.append(son)
            else:
                print("issue?")
                break # prolbem ?
>>> t = WordTree(treeQuestion, treeQuestion[0].label())
<class 'str'> When_WRB_advmod
son creation
<class 'str'> did_VBD_aux
son creation
<class 'str'> Beyonce_NNP_nsubj
son creation
<class 'nltk.tree.Tree'> (becoming_VBG_xcomp popular_JJ_acomp)
sub tree creation
son: (becoming_VBG_xcomp popular_JJ_acomp)
<class 'str'> p
son creation
<class 'str'> o
son creation
<class 'str'> p
se añadieron 782 caracteres en el cuerpo
Origen Enlace

from anytree import Node, RenderTree

class WordTree:
    def __init__(self, array, parent = None):
        #print("son :",array[0][i])
        self.parent = array[0].label()[]
        #selfself.children = [] # if parenthesis then it has son after "," analyse : include all elements until the next parenthesi
        self.data = array
        #print(array[0])
        for elementson in arrayarray[0]:
            print(type(elementson),elementson)
            if type(elementson) is Tree:
                print("sub tree creation")
                t = WordTree(elementson) # should I verify if parent is empty ?
            elif elementtype(son) is stringstr:
                print("son creation")
                self.parent = parent
                self.data = array[0]children.append(son)
            else:
                print("issue?")
                break # prolbem ?

Funciona bien al principio, pero cuando encontramos un subárbol tenemos problemas.

>>> t = WordTree(treeQuestion, treeQuestion[0].label())
<class 'str'> When_WRB_advmod
son creation
<class 'str'> did_VBD_aux
son creation
<class 'str'> Beyonce_NNP_nsubj
son creation
<class 'nltk.tree.Tree'> (becoming_VBG_xcomp popular_JJ_acomp)
sub tree creation
<class 'str'> p
son creation
<class 'str'> o
son creation
<class 'str'> p

Solo toma las letras del subárbol, no las palabras.

from anytree import Node, RenderTree

class WordTree:
    def __init__(self, array):
        self.parent = array[0].label()
        #self.children = []
        self.data = array
        
        for element in array:
            print(type(element),element)
            if type(element) is Tree:
                WordTree(element) # should I verify if parent is empty ?
            elif element is string:
                self.parent = parent
                self.data = array[0]
            else: 
                break # prolbem ?
class WordTree:
    def __init__(self, array, parent = None):
        #print("son :",array[0][i])
        self.parent = []
        self.children = [] # if parenthesis then it has son after "," analyse : include all elements until the next parenthesi
        self.data = array
        #print(array[0])
        for son in array[0]:
            print(type(son),son)
            if type(son) is Tree:
                print("sub tree creation")
                t = WordTree(son) # should I verify if parent is empty ?
            elif type(son) is str:
                print("son creation")
                self.parent = parent
                self.children.append(son)
            else:
                print("issue?")
                break # prolbem ?

Funciona bien al principio, pero cuando encontramos un subárbol tenemos problemas.

>>> t = WordTree(treeQuestion, treeQuestion[0].label())
<class 'str'> When_WRB_advmod
son creation
<class 'str'> did_VBD_aux
son creation
<class 'str'> Beyonce_NNP_nsubj
son creation
<class 'nltk.tree.Tree'> (becoming_VBG_xcomp popular_JJ_acomp)
sub tree creation
<class 'str'> p
son creation
<class 'str'> o
son creation
<class 'str'> p

Solo toma las letras del subárbol, no las palabras.

se eliminaron 331 caracteres en el cuerpo
Origen Enlace
Loading
se añadieron 339 caracteres en el cuerpo
Origen Enlace
Loading
se añadieron 339 caracteres en el cuerpo
Origen Enlace
Loading
se añadieron 315 caracteres en el cuerpo
Origen Enlace
Loading
título editado
Enlace
Loading
se eliminaron 55 caracteres en el cuerpo
Origen Enlace
Loading
Origen Enlace
Loading