Skip to main content

CaboCha output-XML accessor

Project description

Parse XMLs from CaboCha and provides simple tree accessors.

Usage

Expected usages are focused on chunk surfaces and dependency links:

>>> aisansan = xmlpumpkin.parse_to_tree(
...     u'愛燦々とこの身に降って心密かなうれしい涙を流したりして'
... )
>>> len(aisansan.chunks)
8
>>> print(aisansan.root.surface)
流したりして
>>> print(aisansan.root.func_surface)
て
>>> for dep in aisansan.root.linked:
...     print(dep.surface)
...
降って
涙を

You need CaboCha in your path, or shortly with prepared XML:

>>> tree = xmlpumpkin.Tree(xml_as_unicode)

Should you need an easy interface from Python to CaboCha:

>>> from xmlpumpkin import cabocha
>>> print(cabocha.txttree(
...     u'愛燦々とこの身に降って心密かなうれしい涙を流したりして'
... ))
    愛燦々と-----D
          この-D |
            身に-D
            降って-------D
            心密かな---D |
              うれしい-D |
                    涙を-D
              流したりして
EOS
>>> print(cabocha.as_xml(
...     u'愛燦々とこの身に降って心密かなうれしい涙を流したりして'
... ))
<sentence>
  ...
</sentence>

All I/Os are unicodes! If encodings other than UTF-8 is preferred, directly modify following constants:

>>> import xmlpumpkin.runner
>>> xmlpumpkin.runner.CABOCHA_ENCODING = 'SJIS'
>>>
>>> import xmlpumpkin.tree
>>> xmlpumpkin.tree.XML_ENCODING = 'SJIS'

Properties

Not enough but a few properties are provided via Tree and Chunk objects.

class xmlpumpkin.Tree(cabocha_xml)
  • chunks - tuple of chunks

  • root - root (not depending on any chunks) Chunk object

  • chunk_by_id(chunk_id) - get Chunk object by its id generated by CaboCha

  • _element - origin XML as lxml Element object

class xmlpumpkin.Chunk(element, parent)
  • id - chunk id

  • link_to_id - its depending chunk id

  • linked_from_ids - tuple of chunk id depending to this chunk

  • func_id - functional token id of this chunk

  • dep - its depending Chunk object

  • linked - list of all Chunk objects depending to this chunk

  • surface - surface of this chunk

  • func_surface - surface of this chunk’s functional token

  • _tokens() - its containing tokens as lxml Element objects

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

xmlpumpkin-0.1.tar.gz (7.1 kB view details)

Uploaded Source

File details

Details for the file xmlpumpkin-0.1.tar.gz.

File metadata

  • Download URL: xmlpumpkin-0.1.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for xmlpumpkin-0.1.tar.gz
Algorithm Hash digest
SHA256 e512285393a96fbf4680feed1311795cc3dc61162ccbd248db5802f602ccaa56
MD5 8c767bd63e6070cecd87a804acf83405
BLAKE2b-256 21b1f810408b8f548a413c9f2728599940c9e37fea0242d7770bd0a54f5a9a33

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page