Files
old-nlp/venv/lib/python3.7/site-packages/nltk/__pycache__/toolbox.cpython-37.pyc

255 lines
16 KiB
Plaintext
Raw Normal View History

2019-10-20 13:16:49 +02:00
B
D(<28>]NH<00>@s<>dZddlmZddlZddlZddlmZmZmZm Z ddl
m Z ddl m Z mZddlmZmZGdd <09>d e<12>ZGd
d <0B>d e<13>Ze<03>d <0C>Zd#dd<0F>ZGdd<11>de<13>Zd$dd<13>Zdd<15>Zdd<17>Zdd<19>Zdd<1B>Zdd<1D>Zdd<1F>Zd d!<21>Z e!d"k<02>r<>e <20>dS)%zT
Module for reading, writing and manipulating
Toolbox databases and settings files.
<EFBFBD>)<01>print_functionN)<04> ElementTree<65> TreeBuilder<65>Element<6E>
SubElement)<01>u)<02>StringIO<49>PY3)<02> PathPointer<65>findc@sDeZdZdZddd<04>Zdd<06>Zdd<08>Zd d
<EFBFBD>Zdd d<0E>Zdd<10>Z dS)<13>StandardFormatzT
Class for reading and processing standard format marker files and strings.
NcCs||_|dk r|<00>|<01>dS)N)<02> _encoding<6E>open)<03>self<6C>filename<6D>encoding<6E>r<00>./tmp/pip-install-4m6m_5d_/nltk/nltk/toolbox.py<70>__init__szStandardFormat.__init__cCs0t|t<01>r|<01>|j<03>|_nt<05>|d|j<03>|_dS)z<>
Open a standard format marker file for sequential reading.
:param sfm_file: name of the standard format marker input file
:type sfm_file: str
ZrUN)<06>
isinstancer
rr <00>_file<6C>codecs)rZsfm_filerrrr"s
zStandardFormat.opencCst|<01>|_dS)z<>
Open a standard format marker string for sequential reading.
:param s: string to parse as a standard format marker input file
:type s: str
N)rr)r<00>srrr<00> open_string0szStandardFormat.open_stringc cs<>d}d}t<00>|d<00>}t<00>|d<00>}t|j<03>}y t|<05>}Wntk
rNdSXt<00>||<06>}|<07><07>\}} | g}
d|_x\|D]T}|jd7_t<00>||<06>}|<07><07>\} } | r<>||<01> |
<EFBFBD>fV| }| g}
qz|
<EFBFBD>
| <09>qzW|jd7_||<01> |
<EFBFBD>fVdS)z<>
Return an iterator that returns the next field in a (marker, value)
tuple. Linebreaks and trailing white space are preserved except
for the final newline in each field.
:rtype: iter(tuple(str, str))
<20>
z^%s(?:\\(\S+)\s*)?(.*)$u (?:)?<3F>Nr<00>) <0B>re<72>compile<6C>iterr<00>next<78> StopIteration<6F>match<63>groups<70>line_num<75>join<69>append) rZ join_stringZ line_regexpZfirst_line_patZline_patZ file_iter<65>lineZmobj<62>mkrZ
line_valueZ value_linesZline_mkrrrr<00>
raw_fields9s0
   
  zStandardFormat.raw_fieldsT<73>strictc cs<>|dkr|dk rtd<02><01>t<01>d<03>}xx|<00><03>D]l\}}|rrtsr|dk rZ||krZ|<08>d|<04>}n |<08>||<04>}|<07>||<04>}|r<>|<06>d|<08>}|r<>|<08><07>}||fVq,WdS)a<>
Return an iterator that returns the next field in a ``(marker, value)``
tuple, where ``marker`` and ``value`` are unicode strings if an ``encoding``
was specified in the ``fields()`` method. Otherwise they are non-unicode strings.
:param strip: strip trailing whitespace from the last line of each field
:type strip: bool
:param unwrap: Convert newlines in a field to spaces.
:type unwrap: bool
:param encoding: Name of an encoding to use. If it is specified then
the ``fields()`` method returns unicode strings rather than non
unicode strings.
:type encoding: str or None
:param errors: Error handling scheme for codec. Same as the ``decode()``
builtin string method.
:type errors: str
:param unicode_fields: Set of marker names whose values are UTF-8 encoded.
Ignored if encoding is None. If the whole file is UTF-8 encoded set
``encoding='utf8'`` and leave ``unicode_fields`` with its default
value of None.
:type unicode_fields: sequence
:rtype: iter(tuple(str, str))
Nz'unicode_fields is set but not encoding.z\n+<2B>utf8<66> )<08>
ValueErrorrrr)r <00>decode<64>sub<75>rstrip) r<00>strip<69>unwrapr<00>errors<72>unicode_fieldsZ
unwrap_patr(<00>valrrr<00>fields`s
   zStandardFormat.fieldscCs,|j<00><01>y|`Wntk
r&YnXdS)z@Close a previously opened standard format marker file or string.N)r<00>closer$<00>AttributeError)rrrrr7<00>s

zStandardFormat.close)NN)TTNr*N)
<EFBFBD>__name__<5F>
__module__<EFBFBD> __qualname__<5F>__doc__rrrr)r6r7rrrrr s
 )
)r c@s2eZdZd dd<03>Zd dd<05>Zdd<07>Zdd
d <0B>ZdS)<0F> ToolboxDataNcKs(|r|jfd|i|<02><02>S|jf|<02>SdS)N<>grammar)<02> _chunk_parse<73> _record_parse)rr><00>kwargsrrr<00>parse<73>szToolboxData.parsecKs<>t<00>}|<03>di<00>|<03>di<00>d}x<>|jf|<02>D]v\}}|dkrT|sT|ddkrT|}||kr<>|rl|<03>d<07>n|<03>d<02>d}|<03>di<00>|<03>|i<00>|<03>|<06>|<03>|<05>q0W|r<>|<03>d<07>n
|<03>d<02>|<03>d<01>|<03><05>S) a<>
Returns an element tree structure corresponding to a toolbox data file with
all markers at the same level.
Thus the following Toolbox database::
\_sh v3.0 400 Rotokas Dictionary
\_DateStampHasFourDigitYear
\lx kaa
\ps V.A
\ge gag
\gp nek i pas
\lx kaa
\ps V.B
\ge strangle
\gp pasim nek
after parsing will end up with the same structure (ignoring the extra
whitespace) as the following XML fragment after being parsed by
ElementTree::
<toolbox_data>
<header>
<_sh>v3.0 400 Rotokas Dictionary</_sh>
<_DateStampHasFourDigitYear/>
</header>
<record>
<lx>kaa</lx>
<ps>V.A</ps>
<ge>gag</ge>
<gp>nek i pas</gp>
</record>
<record>
<lx>kaa</lx>
<ps>V.B</ps>
<ge>strangle</ge>
<gp>pasim nek</gp>
</record>
</toolbox_data>
:param key: Name of key marker at the start of each record. If set to
None (the default value) the first marker that doesn't begin with
an underscore is assumed to be the key.
:type key: str
:param kwargs: Keyword arguments passed to ``StandardFormat.fields()``
:type kwargs: dict
:rtype: ElementTree._ElementInterface
:return: contents of toolbox data divided into header and records
<20> toolbox_data<74>headerFNr<00>_<>recordT)r<00>startr6<00>end<6E>datar7)r<00>keyrA<00>builderZ
in_recordsr(<00>valuerrrr@<00>s*4   
  
 

zToolboxData._record_parsecCs^ddlm}t|<01><03><00>}x@|D]8}t||<02>r>|<03>|<00>|<04><01>q|\}}t||<06>}||_qW|S)Nr)<01>Tree) <09> nltk.treerMr<00>labelrr&<00> _tree2etreer<00>text)r<00>parentrM<00>root<6F>childrQ<00>tag<61>errrrP<00>s  



zToolboxData._tree2etreerFrc Ks<>ddlm}ddlm}|j|||d<04>}|jf|<04>}td<05>} |<08>d<06>}
| <09>|
<EFBFBD>x6|<08> d<07>D](} |<07>dd <09>| D<00><01>} | <09>|<00>
| <0C><01>q\W| S)
aw
Returns an element tree structure corresponding to a toolbox data file
parsed according to the chunk grammar.
:type grammar: str
:param grammar: Contains the chunking rules used to parse the
database. See ``chunk.RegExp`` for documentation.
:type root_label: str
:param root_label: The node value that should be used for the
top node of the chunk structure.
:type trace: int
:param trace: The level of tracing that should be used when
parsing a text. ``0`` will generate no tracing output;
``1`` will generate normal tracing output; and ``2`` or
higher will generate verbose tracing output.
:type kwargs: dict
:param kwargs: Keyword arguments passed to ``toolbox.StandardFormat.fields()``
:rtype: ElementTree._ElementInterface
r)<01>chunk)rM)<02>
root_label<EFBFBD>tracerCrDrFcSsg|]}|j|jf<02>qSr)rQrU)<02>.0<EFBFBD>elemrrr<00>
<listcomp>sz,ToolboxData._chunk_parse.<locals>.<listcomp>) ZnltkrWrNrMZ RegexpParserrBrr r&<00>findallrP) rr>rXrYrArWrM<00>cp<63>dbZtb_etreerDrF<00>parsedrrrr?<00>s   

zToolboxData._chunk_parse)N)N)NrFr)r9r:r;rBr@rPr?rrrrr=<00>s

L r=z\Sr*c Cs4|jdkr td<02>}|<04>|<00>|}|jdkr2td<03><01>|dkrJ|dk rJtd<05><01>g}x<>|D]<5D>}|<05>d<06>x<>|D]<5D>}|j}|j} |dk r<>|dk r<>||kr<>d}
n|}
t<05>t| <09>r<>|<05>td<08>|| f<00> |
|<02><02>n|<05>td <09>|| f<00> |
|<02><02>qht<05>t| <09><02>r|<05>d|| f<00>qh|<05>d || f<00>qhWqTWd
<EFBFBD>
|d d<04><00>S) a@
Return a string with a standard format representation of the toolbox
data in tree (tree can be a toolbox database or a single record).
:param tree: flat representation of toolbox data (whole database or single record)
:type tree: ElementTree._ElementInterface
:param encoding: Name of an encoding to use.
:type encoding: str
:param errors: Error handling scheme for codec. Same as the ``encode()``
builtin string method.
:type errors: str
:param unicode_fields:
:type unicode_fields: dict(str) or set(str)
:rtype: str
rFrCz$not a toolbox_data element structureNz?if encoding is not specified then neither should unicode_fieldsrr+z\%s %s
z\%s%s
rr) rUrr&r-rQr<00>search<63> _is_valuer<00>encoder%) <0B>treerr3r4rS<00>lZrec<65>fieldr(rLZ cur_encodingrrr<00> to_sfm_strings8





 rgcs*eZdZdZ<03>fdd<03>Zddd<07>Z<05>ZS) <09>ToolboxSettingsz0This class is the base class for settings files.cstt|<00><02><02>dS)N)<03>superrhr)r)<01> __class__rrrVszToolboxSettings.__init__Nr*cKs<>t<00>}x<>|jf||d<01>|<03><02>D]~\}}|d}|dkrD|dd<05>}nd}|dkrh|<04>|i<00>|<04>|<06>q|dkr||<04>|<05>q|<04>|i<00>|<04>|<06>|<04>|<05>qW|<04><05>S)a<>
Return the contents of toolbox settings file with a nested structure.
:param encoding: encoding used by settings file
:type encoding: str
:param errors: Error handling scheme for codec. Same as ``decode()`` builtin method.
:type errors: str
:param kwargs: Keyword arguments passed to ``StandardFormat.fields()``
:type kwargs: dict
:rtype: ElementTree._ElementInterface
)rr3r)<02>+<2B>-rNrkrl)rr6rGrIrHr7)rrr3rArKr(rL<00>blockrrrrBYs      
zToolboxSettings.parse)Nr*)r9r:r;r<rrB<00> __classcell__rr)rjrrhSs rhcCs&t<00>}t|<00><02>||||d<01>d<02>|<04>S)N)rr3r4r)<04>list<73>_to_settings_string<6E>getrootr%)rdrr3r4rerrr<00>to_settings_string{srrcKs<>|j}|j}t|<00>dkr@|r0|<01>d||f<00>q<>|<01>d|<00>nP|rX|<01>d||f<00>n|<01>d|<00>x|D]}t||f|<02>qlW|<01>d|<00>dS)Nrz\%s %s
z\%s
z\+%s %s
z\+%s
z\-%s
)rUrQ<00>lenr&rp)<06>nodererArUrQ<00>nrrrrp<00>s 
rpcCsHt<00>}x0|D](}t|<02>|js*t|<02>dkr |<01>|<02>q W||dd<02><dS)z<>
Remove all elements and subelements with no text and no child elements.
:param elem: toolbox data in an elementtree structure
:type elem: ElementTree._ElementInterface
rN)ro<00> remove_blanksrQrsr&)r[<00>outrTrrrrv<00>s 
rvcCsLx.|<01>|jg<00>D]}|<00>|<02>dkrt||<02>qWx|D]}t||<01>q6WdS)a(
Add blank elements and subelements specified in default_fields.
:param elem: toolbox data in an elementtree structure
:type elem: ElementTree._ElementInterface
:param default_fields: fields to add to each type of element and subelement
:type default_fields: dict(tuple)
N)<05>getrUr r<00>add_default_fields)r[Zdefault_fieldsrfrTrrrry<00>s

rycCsVt<00>}x@|<01><01>D]4\}}t<00>||<}xt|<04>D]\}}|||<q0WqWt||<02>dS)a-
Sort the elements and subelements in order specified in field_orders.
:param elem: toolbox data in an elementtree structure
:type elem: ElementTree._ElementInterface
:param field_orders: order of fields for each type of element and subelement
:type field_orders: dict(tuple)
N)<04>dict<63>items<6D> enumerate<74> _sort_fields)r[Z field_ordersZ order_dictsrf<00>orderZ order_key<65>iZsubfieldrrr<00> sort_fields<64>s r<>csxy||j<00>Wntk
r"Yn2Xt<02>fdd<02>t|<00>D<00><01>}dd<02>|D<00>|dd<04><x|D]}t|<03>rZt||<01>qZWdS)zsort the children of elemcs&g|]\}}<02><00>|jd<00>|f|f<02>qS)ge<><65>A)rxrU)rZrrT)r~rrr\<00>sz _sort_fields.<locals>.<listcomp>cSsg|] \}}|<02>qSrr)rZrJrTrrrr\<00>sN)rU<00>KeyError<6F>sortedr|rsr})r[Z orders_dicts<74>tmprTr)r~rr}<00>s
r}c Cs<>y||j}||j}Wn6tk
rNx |D]}t|<05>r.t|||<02>q.WYn<>Xd}x<>|D]<5D>}|j}|dk r<>|j|kr<>||kr<>|dk r<>|<06><04>d}|jp<>dd|_n$||kr<>|<06><04>d}|jp<>dd|_t|<05>r<>t|||<02>|}qZWdS)a1
Add blank lines before all elements and subelements specified in blank_before.
:param elem: toolbox data in an elementtree structure
:type elem: ElementTree._ElementInterface
:param blank_before: elements and subelements to add blank lines before
:type blank_before: dict(tuple)
N<><4E><EFBFBD><EFBFBD><EFBFBD>rr)rUr<>rs<00>add_blank_lines<65> getiteratorrQ) rdZ blanks_beforeZblanks_between<65>beforeZbetweenr[Z last_elemrUrVrrrr<><00>s( 


   r<>cCs<>ddlm}td<03>}t|<01><01><04>}td<04>t|ddj<06>t|ddj<07>td<06>x&||<02>d<07>d<08>D]}t|j|j<07>qfWtd <09>x"||<02>d
<EFBFBD>d<08>D]}t|j<07>q<>Wt <09>}td <0B>}|<04>
|<01>|jd d d<0E>}t|<05>d<0F>j<07>t |<05>}tt |<06><01> d<10><01>dS)Nr)<01>islicezcorpora/toolbox/rotokas.diczfirst field in fourth record:<3A>z
fields in sequential order:rF<00>
z
lx fields:z record/lxz corpora/toolbox/MDF/MDF_AltH.typF<70>cp1252)r2rz$expset/expMDF/rtfPageSetup/paperSizer+)<0E> itertoolsr<73>r r=rB<00>printrUrQr]rhrrrrrc)r<><00> file_path<74>lexiconrf<00>settingsrdZ settings_treerrr<00>demo<6D>s&  
r<><00>__main__)Nr*N)Nr*N)"r<<00>
__future__rrr<00>xml.etree.ElementTreerrrr<00>sixrZ nltk.compatrr Z nltk.datar
r <00>objectr r=rrbrgrhrrrprvryr<>r}r<>r<>r9rrrr<00><module> s.  

6(
!