Skip to content

Commit

Permalink
Added a TextualBody class and the parsing of a bodyValue property def…
Browse files Browse the repository at this point in the history
…ined

on an annotation to a TextualBody resource as an annotation body
  • Loading branch information
vincentmarchetti committed Aug 12, 2024
1 parent 983d702 commit a607494
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/Annotation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import {
IManifestoOptions,
ManifestResource,
Resource,
SpecificResource
SpecificResource,
TextualBody
} from "./internal";

import { Vector3 } from "threejs-math";
Expand All @@ -23,6 +24,28 @@ export class Annotation extends ManifestResource {
**/
getBody(): ( AnnotationBody | SpecificResource) [] {
let bodies: ( AnnotationBody | SpecificResource)[] = [];

/*
A bodyValue property in the annotation json will short circuit
the parsing process and be interpreted as a shorthand version of
a TextualBody resource defining as the body
This procedure is allowed, see Web Annotation Data Model section 3.2.5
https://www.w3.org/TR/annotation-model/#string-body
*/

var stringBody : string | undefined = this.getProperty("bodyValue");
//console.log("retrieved stringBody " + stringBody);
if (stringBody){
return [new TextualBody(
{ "id" : "https://example.com/TextualBody/1",
"value" : stringBody,
"type" : "TextualBody"
},
this.options
)];
}

const body: any = this.getProperty("body");

// the following is intended to handle the following cases for
Expand Down
30 changes: 30 additions & 0 deletions src/TextualBody.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import {
IManifestoOptions,
AnnotationBody} from "./internal";

/**
An implementation of the TextualBody class (class in JSON-LD sense)
as it is described in Web Annotation Data Model Section 3.2.4
https://www.w3.org/TR/annotation-model/#embedded-textual-body
**/
export class TextualBody extends AnnotationBody {
constructor(jsonld?: any, options?: IManifestoOptions) {
super(jsonld, options);
this.isModel = false;
this.isLight = false;
this.isCamera = false;
}

/**
identify an instance of this typescript as representing a resource
having these json-ld Class relationships.
**/
get isTextualBody() : boolean { return true;}
get isText() : boolean {return true;}

/**
The simple string that is the data content of this resource
will return empty string as a default value
**/
get Value(): string {return this.getProperty("value") || "" ;}
}
1 change: 1 addition & 0 deletions src/internal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export * from "./SpecificResource";
export * from "./AnnotationBody";
export * from "./Light";
export * from "./Camera";
export * from "./TextualBody";
export * from "./AnnotationBodyParser";
export * from "./Annotation";

Expand Down

0 comments on commit a607494

Please sign in to comment.