Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upload/download annotations and documents to/from CAS #7

Open
reckart opened this issue Feb 18, 2022 · 2 comments
Open

Upload/download annotations and documents to/from CAS #7

reckart opened this issue Feb 18, 2022 · 2 comments
Labels
⭐️ Enhancement New feature or request

Comments

@reckart
Copy link
Member

reckart commented Feb 18, 2022

It would be nice if there were convenience upload/download methods that directly accept DKPro Cassis Cas objects.

For uploading, the Cas object can be serialized to XMI and uploaded.

For downloading, INCEpTION exports XMIs actually as ZIP files containing a type system file and the XMI file - this can be converted to a Cas object using code like this:

with TemporaryDirectory() as tmpdir:
        with ZipFile(BytesIO(pycaprio.api.annotation(1, 4, annotation_format=InceptionFormat.XMI))) as xmi_zip:
            type_system = load_typesystem(BytesIO(xmi_zip.read('TypeSystem.xml')))
            for i in xmi_zip.filelist:
                if i.filename.endswith('.xmi'):
                    cas = load_cas_from_xmi(BytesIO(xmi_zip.read(i)), typesystem=type_system)
                    break # There is only one XMI per ZIP
@JavierLuna
Copy link
Collaborator

That's a great idea!
How can I get a Cas object to try it myself?

@reckart
Copy link
Member Author

reckart commented Mar 13, 2022

One way to create one is (using cassis - examples here: https://github.com/dkpro/dkpro-cassis):

cas = Cas()
cas.sofa_string = "I like cheese ."

But for upload, they'd normally come from files, e.g.:

with open('typesystem.xml', 'rb') as f:
    typesystem = load_typesystem(f)

with open('cas.xml', 'rb') as f:
    cas = load_cas_from_xmi(f, typesystem=typesystem)

of if the user has exported an XMI for example from the INCEpTION annotation page, then it's the same as above with the type system and XMI files being in a ZIP.

@reckart reckart added the ⭐️ Enhancement New feature or request label Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
⭐️ Enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants