Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #103568

Error in Tree Structure

X-Received by 10.50.47.40 with SMTP id a8mr1770248ign.6.1456564665411; Sat, 27 Feb 2016 01:17:45 -0800 (PST)
X-Received by 10.50.35.165 with SMTP id i5mr33589igj.0.1456564665394; Sat, 27 Feb 2016 01:17:45 -0800 (PST)
Path csiph.com!usenet.blueworldhosting.com!feeder01.blueworldhosting.com!news.glorb.com!hb3no9462758igb.0!news-out.google.com!k1ni2434igd.0!nntp.google.com!hb3no9462748igb.0!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail
Newsgroups comp.lang.python
Date Sat, 27 Feb 2016 01:17:45 -0800 (PST)
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=122.162.100.85; posting-account=6SonuQoAAACzSakS5dCECcJQe6ylLrzY
NNTP-Posting-Host 122.162.100.85
User-Agent G2/1.0
MIME-Version 1.0
Message-ID <33c93316-0ae3-4b8f-b2f6-29f76c8b3f32@googlegroups.com> (permalink)
Subject Error in Tree Structure
From subhabangalore@gmail.com
Injection-Date Sat, 27 Feb 2016 09:17:45 +0000
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Xref csiph.com comp.lang.python:103568

Show key headers only | View raw


I was trying to implement the code, 

import nltk
import nltk.tag, nltk.chunk, itertools
def ieertree2conlltags(tree, tag=nltk.tag.pos_tag):
    words, ents = zip(*tree.pos())
    iobs = []
    prev = None
    for ent in ents:
        if ent == tree.node:
            iobs.append('O')
            prev = None
        elif prev == ent:
             iobs.append('I-%s' % ent)
        else:
             iobs.append('B-%s' % ent)
             prev = ent
    words, tags = zip(*tag(words))
    return itertools.izip(words, tags, iobs)

def ieer_chunked_sents(tag=nltk.tag.pos_tag):
    for doc in ieer.parsed_docs():
        tagged = ieertree2conlltags(doc.text, tag)
        yield nltk.chunk.conlltags2tree(tagged)

                
from chunkers import ieer_chunked_sents, ClassifierChunker
from nltk.corpus import treebank_chunk
ieer_chunks = list(ieer_chunked_sents())
chunker = ClassifierChunker(ieer_chunks[:80])
print chunker.parse(treebank_chunk.tagged_sents()[0])
score = chunker.evaluate(ieer_chunks[80:])
print score.accuracy()

It is running fine. 
But as I am trying to rewrite the code as,
chunker = ClassifierChunker(list1),
where list1 is same value as,
ieer_chunks[:80]
only I am pasting the value as 
[Tree('S', [Tree('LOCATION', [(u'NAIROBI', 'NNP')]), (u',', ','), Tree('LOCATION', [(u'Kenya', 'NNP')]), (u'(', '('), Tree('ORGANIZATION', [(u'AP', 'NNP')]), (u')', ')'), (u'_', 'NNP'), Tree('CARDINAL', [(u'Thousands', 'NNP')]), (u'of', 'IN'), (u'laborers,', 'JJ'), (u'students', 'NNS'), (u'and', 'CC'), (u'opposition', 'NN'), (u'politicians', 'NNS'), (u'on', 'IN'), Tree('DATE', [(u'Saturday', 'NNP')]), (u'protested', 'VBD'), (u'tax', 'NN'), (u'hikes', 'NNS'), (u'imposed', 'VBN'), (u'by', 'IN'), (u'their', 'PRP$'), (u'cash-strapped', 'JJ'), (u'government,', 'NN'), (u'which', 'WDT'), (u'they', 'PRP'), (u'accused', 'VBD'), (u'of', 'IN'), (u'failing', 'VBG'), (u'to', 'TO'), (u'provide', 'VB'), (u'basic', 'JJ'), (u'services.', 'NN'),....(u'(cm-kjd)', 'NN')])]
the value of whole list directly I am getting syntax error.
I tried to paste it in Python IDE outside code there also it is giving syntax error. 
If I do not paste the value and and rename ieer_chunks[:80] as list1 there is no error.
I may be doing some problem while copying the value and pasting it. 
But I did not change anything there.

Is it any error in Python part or in NLTK part? 

Thanks in advance.
If any one may guide me what is the error I am doing and how may I solve it.


 

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Error in Tree Structure subhabangalore@gmail.com - 2016-02-27 01:17 -0800
  Re: Error in Tree Structure Steven D'Aprano <steve@pearwood.info> - 2016-02-27 22:29 +1100
  Re: Error in Tree Structure Rustom Mody <rustompmody@gmail.com> - 2016-02-27 08:13 -0800
    Re: Error in Tree Structure subhabangalore@gmail.com - 2016-02-29 09:23 -0800

csiph-web