OpenPecha / Toolkit

🛠 Tools to create, edit and export texts and annotations
https://toolkit.openpecha.org
Apache License 2.0
7 stars 4 forks source link

Layers not initialised when loading existing opf #227

Open 10zintopjor opened 1 year ago

10zintopjor commented 1 year ago

Is your feature request related to a problem? Please describe. i am trying to get the layers from openpechaFS given a created opf Path to it,however the layers attribute is empty when accessing through the object.

Describe the solution you'd like if the given path is already created,then the layers can be initialise.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context

eroux commented 1 year ago

The description is a bit unclear... in the case you're looking at, are there existing layer files? If not, it seems quite normal that the layer object is empty

10zintopjor commented 1 year ago

I am passing an already created opf that is downloaded from Openpecha-Data to openpechaFS and it has layers.The main problem is that i need what type of layer exist in a particular opf.

eroux commented 1 year ago

ok yes, then that seems like an issue, can you create a minimal working example demonstrating your bug?

10zintopjor commented 1 year ago

The function returns empty list even though the pecha has layers.

from openpecha.core.pecha import OpenPechaFS

def get_opf_layers(pecha_path):
    opf = OpenPechaFS(pecha_path)
    opf_layers = opf.layers
    return opf_layers
eroux commented 1 year ago

A minimal working example is an example that actually works if I test it but if I run your code nothing will happen. Please provide some code that I can run to reproduce the issue

10zintopjor commented 1 year ago

I have added the MRE in this repo.The main function gets the layer types of opf and then it updates a catalog.

MRE

eroux commented 1 year ago

wonderful, thanks!

eroux commented 1 year ago

I can't push code to your repo, but here's a mre.py that works:

from openpecha.core.pecha import OpenPechaFS

def get_opf_layers(opf_path):
    opf = OpenPechaFS(opf_path)
    layers = []
    for base in opf.meta.bases:
        layers = list(opf.get_layers(base))
    return layers

if __name__ == "__main__":
    pecha_id = "I4AEA9D55"
    opf_path = "./I4AEA9D55/I4AEA9D55.opf"
    print("opf has %d layers" % len(get_opf_layers(opf_path)))