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

Accessing v3 canvas annotations #125

Open
jonw-cogapp opened this issue Aug 9, 2023 · 1 comment
Open

Accessing v3 canvas annotations #125

jonw-cogapp opened this issue Aug 9, 2023 · 1 comment

Comments

@jonw-cogapp
Copy link

Question / feature request:

Unless I'm mistaken it seems like manifesto doesn't currently provide methods for directly obtaining embedded annotations in v3 manifests — those that exist in the annotations array at the canvas level.

Here are some example recipes from the cookbook that show the structure I'd like to access:

For my own needs I've been able to use getProperty("annotations") on a canvas to iterate and instantiate annotations with the appropriate manifesto constructors (this only covers something similar to the tagging recipe), like so:

  type RawAnnotationPage = {
    id: string;
    type: string;
    items: Array<RawAnnotation>;
  };

  type RawAnnotation = {
    id: string;
    type: string;
    motivation: string;
    body: RawAnnotationBody;
    target: string;
  };

  type RawAnnotationBody = {
    type: string;
    value: string;
    language: string;
    format: string;
  };

  function getAnnotationPages(canvases: Canvas[], options: Manifest["options"]): Array<AnnotationPage> {
    const annotationPages: Array<AnnotationPage> = [];

    if (canvases.length) {
      canvases.forEach((canvas) => {
        // "getProperty" ejects and results in raw JSON
        // We need to instantiate each level with the appropriate constructor
        const rawAnnotationPages: Array<RawAnnotationPage> =
          canvas.getProperty("annotations") || [];

        annotationPages.push(
          ...rawAnnotationPages.map((rawAnnotationPage) => {
            const rawAnnotations: Array<RawAnnotation> | undefined =
              rawAnnotationPage.items;

            return new AnnotationPage(
              {
                ...rawAnnotationPage,
                items: rawAnnotations.map((rawAnnotation) => {
                  return new Annotation(rawAnnotation, options);
                }),
                type: rawAnnotationPage.type,
              },
              options,
            );
          }),
        );
        return [];
      });
    }
    return annotationPages;
  }

But it would be really cool if there was ways of accessing these annotations with methods directly in manifesto.

@cmahnke
Copy link
Contributor

cmahnke commented Oct 12, 2024

@jonw-cogapp: Have you tried to create a PR for this? I'm not sure if this project is still active...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants