@semiont/ontology 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -6,14 +6,15 @@
6
6
  [![npm downloads](https://img.shields.io/npm/dm/@semiont/ontology.svg)](https://www.npmjs.com/package/@semiont/ontology)
7
7
  [![License](https://img.shields.io/npm/l/@semiont/ontology.svg)](https://github.com/The-AI-Alliance/semiont/blob/main/LICENSE)
8
8
 
9
- Entity types, tag schemas, and tag extraction utilities for the Semiont annotation system.
9
+ Entity types and annotation-body extraction utilities for the Semiont annotation system.
10
10
 
11
11
  ## Overview
12
12
 
13
- This package consolidates ontology-related code that was previously scattered across the codebase:
14
- - **Entity types**: Semantic categories for tagging resources and annotations (Person, Organization, Location, etc.)
15
- - **Tag schemas**: Structural analysis frameworks (IRAC for legal, IMRAD for scientific, Toulmin for argumentation)
16
- - **Tag extraction**: Utilities for extracting tag information from W3C annotations
13
+ This package owns:
14
+ - **Entity types**: Semantic categories for tagging resources and annotations (Person, Organization, Location, etc.) — `DEFAULT_ENTITY_TYPES` plus the extraction helper `getEntityTypes`.
15
+ - **Tag extraction helpers**: Pure body-readers (`getTagCategory`, `getTagSchemaId`) that pull schema provenance off an annotation's body. They don't depend on the schema registry.
16
+
17
+ **Tag schemas are not stored in this package.** Schemas are runtime-registered per knowledge base via `frame.addTagSchema(...)` from the SDK; the `TagSchema` and `TagCategory` *types* are exported from `@semiont/core`. The schema *data* lives with the KB that owns it (typically a `src/tag-schemas.ts` module in the KB repo).
17
18
 
18
19
  ## Installation
19
20
 
@@ -37,34 +38,20 @@ console.log(DEFAULT_ENTITY_TYPES);
37
38
 
38
39
  ### Tag Schemas
39
40
 
40
- Three built-in tag schemas for structural document analysis:
41
+ Tag schemas are runtime-registered per KB (see [`docs/protocol/skills/semiont-tag/SKILL.md`](../../docs/protocol/skills/semiont-tag/SKILL.md) and [`.plans/TAG-SCHEMAS-GAP.md`](../../.plans/TAG-SCHEMAS-GAP.md)). The `TagSchema` and `TagCategory` *types* live in `@semiont/core`; schema *data* lives with the KB that owns it. Use `frame.addTagSchema(schema)` to register and `browse.tagSchemas()` to enumerate registered schemas.
41
42
 
42
43
  ```typescript
43
- import {
44
- TAG_SCHEMAS,
45
- getTagSchema,
46
- getAllTagSchemas,
47
- getTagSchemasByDomain
48
- } from '@semiont/ontology';
49
-
50
- // Get a specific schema
51
- const iracSchema = getTagSchema('legal-irac');
52
- // Returns: { id: 'legal-irac', name: 'Legal Analysis (IRAC)',
53
- // domain: 'legal', tags: [...] }
54
-
55
- // Get all schemas
56
- const allSchemas = getAllTagSchemas();
57
- // Returns array of all 3 schemas
58
-
59
- // Get schemas by domain
60
- const legalSchemas = getTagSchemasByDomain('legal');
61
- // Returns schemas where domain === 'legal'
62
- ```
44
+ import { SemiontClient, type TagSchema } from '@semiont/sdk';
63
45
 
64
- Available schemas (from [src/tag-schemas.ts](src/tag-schemas.ts)):
65
- - `legal-irac`: Legal Analysis (IRAC) - Issue, Rule, Application, Conclusion
66
- - `scientific-imrad`: Scientific Paper (IMRAD) - Introduction, Methods, Results, Discussion
67
- - `argument-toulmin`: Argument Structure (Toulmin) - Claim, Evidence, Warrant, Counterargument, Rebuttal
46
+ const semiont = await SemiontClient.signInHttp({ /* ... */ });
47
+
48
+ // Register a schema (idempotent same content re-registered is silent)
49
+ const SCHEMA: TagSchema = { id: 'my-schema', name: '...', /* ... */ };
50
+ await semiont.frame.addTagSchema(SCHEMA);
51
+
52
+ // Enumerate registered schemas
53
+ const all = await semiont.browse.tagSchemas();
54
+ ```
68
55
 
69
56
  ### Entity Extraction
70
57
 
@@ -117,30 +104,6 @@ const schemaId = getTagSchemaId(tagAnnotation);
117
104
 
118
105
  From [src/tag-extraction.ts](src/tag-extraction.ts): Tag annotations use dual-body structure with `purpose: 'tagging'` for category and `purpose: 'classifying'` for schema ID.
119
106
 
120
- ### Tag Schema Helpers
121
-
122
- ```typescript
123
- import { isValidCategory, getSchemaCategory } from '@semiont/ontology';
124
-
125
- // Check if a category exists in a schema
126
- const isValid = isValidCategory('legal-irac', 'Issue');
127
- // Returns: true
128
-
129
- const invalid = isValidCategory('legal-irac', 'Conclusion');
130
- // Returns: true (all 4 IRAC categories are valid)
131
-
132
- const notValid = isValidCategory('legal-irac', 'Introduction');
133
- // Returns: false (Introduction is IMRAD, not IRAC)
134
-
135
- // Get category details
136
- const category = getSchemaCategory('legal-irac', 'Rule');
137
- // Returns: {
138
- // name: 'Rule',
139
- // description: 'The relevant law, statute, or legal principle',
140
- // examples: ['What law applies?', 'What is the legal standard?', ...]
141
- // }
142
- ```
143
-
144
107
  ## Tag Collections
145
108
 
146
109
  Type definitions for graph database tag collection operations:
@@ -181,10 +144,8 @@ packages/ontology/
181
144
  │ ├── index.ts # Public API exports
182
145
  │ ├── entity-types.ts # DEFAULT_ENTITY_TYPES
183
146
  │ ├── tag-collections.ts # TagCollection interfaces
184
- │ ├── tag-schemas.ts # TAG_SCHEMAS registry
185
147
  │ ├── entity-extraction.ts # getEntityTypes utility
186
- ├── tag-extraction.ts # getTagCategory, getTagSchemaId
187
- │ └── bootstrap.ts # Re-export note (actual bootstrap in backend)
148
+ └── tag-extraction.ts # getTagCategory, getTagSchemaId
188
149
  ├── package.json
189
150
  ├── tsconfig.json
190
151
  ├── tsup.config.ts
package/dist/index.d.ts CHANGED
@@ -44,49 +44,6 @@ interface TagCollectionOperations {
44
44
  initializeCollections(): Promise<void>;
45
45
  }
46
46
 
47
- /**
48
- * Tag Schema Registry
49
- *
50
- * Defines structural analysis frameworks for automatic tagging detection.
51
- * Each schema provides categories that passages can be classified into
52
- * based on their structural role (not their semantic content).
53
- *
54
- * Examples: IRAC (legal), IMRAD (scientific), Toulmin (argumentation)
55
- */
56
- interface TagCategory {
57
- name: string;
58
- description: string;
59
- examples: string[];
60
- }
61
- interface TagSchema {
62
- id: string;
63
- name: string;
64
- description: string;
65
- domain: 'legal' | 'scientific' | 'general';
66
- tags: TagCategory[];
67
- }
68
- declare const TAG_SCHEMAS: Record<string, TagSchema>;
69
- /**
70
- * Get a tag schema by ID
71
- */
72
- declare function getTagSchema(schemaId: string): TagSchema | null;
73
- /**
74
- * Get all available tag schemas
75
- */
76
- declare function getAllTagSchemas(): TagSchema[];
77
- /**
78
- * Get tag schemas filtered by domain
79
- */
80
- declare function getTagSchemasByDomain(domain: 'legal' | 'scientific' | 'general'): TagSchema[];
81
- /**
82
- * Validate that a category name is valid for a schema
83
- */
84
- declare function isValidCategory(schemaId: string, categoryName: string): boolean;
85
- /**
86
- * Get a specific category from a schema
87
- */
88
- declare function getSchemaCategory(schemaId: string, categoryName: string): TagCategory | null;
89
-
90
47
  /**
91
48
  * Entity Type Extraction Utilities
92
49
  *
@@ -128,4 +85,4 @@ declare function getTagCategory(annotation: Annotation): string | undefined;
128
85
  */
129
86
  declare function getTagSchemaId(annotation: Annotation): string | undefined;
130
87
 
131
- export { DEFAULT_ENTITY_TYPES, TAG_SCHEMAS, type TagCategory, type TagCollection, type TagCollectionOperations, type TagSchema, getAllTagSchemas, getEntityTypes, getSchemaCategory, getTagCategory, getTagSchema, getTagSchemaId, getTagSchemasByDomain, isValidCategory };
88
+ export { DEFAULT_ENTITY_TYPES, type TagCollection, type TagCollectionOperations, getEntityTypes, getTagCategory, getTagSchemaId };
package/dist/index.js CHANGED
@@ -11,170 +11,6 @@ var DEFAULT_ENTITY_TYPES = [
11
11
  "Author"
12
12
  ];
13
13
 
14
- // src/tag-schemas.ts
15
- var TAG_SCHEMAS = {
16
- "legal-irac": {
17
- id: "legal-irac",
18
- name: "Legal Analysis (IRAC)",
19
- description: "Issue, Rule, Application, Conclusion framework for legal reasoning",
20
- domain: "legal",
21
- tags: [
22
- {
23
- name: "Issue",
24
- description: "The legal question or problem to be resolved",
25
- examples: [
26
- "What is the central legal question?",
27
- "What must the court decide?",
28
- "What is the dispute about?"
29
- ]
30
- },
31
- {
32
- name: "Rule",
33
- description: "The relevant law, statute, or legal principle",
34
- examples: [
35
- "What law applies?",
36
- "What is the legal standard?",
37
- "What statute governs this case?"
38
- ]
39
- },
40
- {
41
- name: "Application",
42
- description: "How the rule applies to the specific facts",
43
- examples: [
44
- "How does the law apply to these facts?",
45
- "Analysis of the case",
46
- "How do the facts satisfy the legal standard?"
47
- ]
48
- },
49
- {
50
- name: "Conclusion",
51
- description: "The resolution or outcome based on the analysis",
52
- examples: [
53
- "What is the court's decision?",
54
- "What is the final judgment?",
55
- "What is the holding?"
56
- ]
57
- }
58
- ]
59
- },
60
- "scientific-imrad": {
61
- id: "scientific-imrad",
62
- name: "Scientific Paper (IMRAD)",
63
- description: "Introduction, Methods, Results, Discussion structure for research papers",
64
- domain: "scientific",
65
- tags: [
66
- {
67
- name: "Introduction",
68
- description: "Background, context, and research question",
69
- examples: [
70
- "What is the research question?",
71
- "Why is this important?",
72
- "What is the hypothesis?"
73
- ]
74
- },
75
- {
76
- name: "Methods",
77
- description: "Experimental design and procedures",
78
- examples: [
79
- "How was the study conducted?",
80
- "What methods were used?",
81
- "What was the experimental design?"
82
- ]
83
- },
84
- {
85
- name: "Results",
86
- description: "Findings and observations",
87
- examples: [
88
- "What did the study find?",
89
- "What are the data?",
90
- "What were the observations?"
91
- ]
92
- },
93
- {
94
- name: "Discussion",
95
- description: "Interpretation and implications of results",
96
- examples: [
97
- "What do the results mean?",
98
- "What are the implications?",
99
- "How do these findings relate to prior work?"
100
- ]
101
- }
102
- ]
103
- },
104
- "argument-toulmin": {
105
- id: "argument-toulmin",
106
- name: "Argument Structure (Toulmin)",
107
- description: "Claim, Evidence, Warrant, Counterargument, Rebuttal framework for argumentation",
108
- domain: "general",
109
- tags: [
110
- {
111
- name: "Claim",
112
- description: "The main assertion or thesis",
113
- examples: [
114
- "What is being argued?",
115
- "What is the main point?",
116
- "What position is being taken?"
117
- ]
118
- },
119
- {
120
- name: "Evidence",
121
- description: "Data or facts supporting the claim",
122
- examples: [
123
- "What supports this claim?",
124
- "What are the facts?",
125
- "What data is provided?"
126
- ]
127
- },
128
- {
129
- name: "Warrant",
130
- description: "Reasoning connecting evidence to claim",
131
- examples: [
132
- "Why does this evidence support the claim?",
133
- "What is the logic?",
134
- "How does this reasoning work?"
135
- ]
136
- },
137
- {
138
- name: "Counterargument",
139
- description: "Opposing viewpoints or objections",
140
- examples: [
141
- "What are the objections?",
142
- "What do critics say?",
143
- "What are alternative views?"
144
- ]
145
- },
146
- {
147
- name: "Rebuttal",
148
- description: "Response to counterarguments",
149
- examples: [
150
- "How is the objection addressed?",
151
- "Why is the counterargument wrong?",
152
- "How is the criticism answered?"
153
- ]
154
- }
155
- ]
156
- }
157
- };
158
- function getTagSchema(schemaId) {
159
- return TAG_SCHEMAS[schemaId] || null;
160
- }
161
- function getAllTagSchemas() {
162
- return Object.values(TAG_SCHEMAS);
163
- }
164
- function getTagSchemasByDomain(domain) {
165
- return Object.values(TAG_SCHEMAS).filter((schema) => schema.domain === domain);
166
- }
167
- function isValidCategory(schemaId, categoryName) {
168
- const schema = getTagSchema(schemaId);
169
- if (!schema) return false;
170
- return schema.tags.some((tag) => tag.name === categoryName);
171
- }
172
- function getSchemaCategory(schemaId, categoryName) {
173
- const schema = getTagSchema(schemaId);
174
- if (!schema) return null;
175
- return schema.tags.find((tag) => tag.name === categoryName) || null;
176
- }
177
-
178
14
  // src/entity-extraction.ts
179
15
  function getEntityTypes(annotation) {
180
16
  if (Array.isArray(annotation.body)) {
@@ -222,14 +58,8 @@ function getTagSchemaId(annotation) {
222
58
  }
223
59
  export {
224
60
  DEFAULT_ENTITY_TYPES,
225
- TAG_SCHEMAS,
226
- getAllTagSchemas,
227
61
  getEntityTypes,
228
- getSchemaCategory,
229
62
  getTagCategory,
230
- getTagSchema,
231
- getTagSchemaId,
232
- getTagSchemasByDomain,
233
- isValidCategory
63
+ getTagSchemaId
234
64
  };
235
65
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/entity-types.ts","../src/tag-schemas.ts","../src/entity-extraction.ts","../src/tag-extraction.ts"],"sourcesContent":["/**\n * Default entity types for the Semiont system\n *\n * Entity types are used to tag resources and annotations with semantic categories.\n * These types serve as initial seed data for the entity types collection.\n */\nexport const DEFAULT_ENTITY_TYPES = [\n 'Person',\n 'Organization',\n 'Location',\n 'Event',\n 'Concept',\n 'Product',\n 'Technology',\n 'Date',\n 'Author'\n];\n","/**\n * Tag Schema Registry\n *\n * Defines structural analysis frameworks for automatic tagging detection.\n * Each schema provides categories that passages can be classified into\n * based on their structural role (not their semantic content).\n *\n * Examples: IRAC (legal), IMRAD (scientific), Toulmin (argumentation)\n */\n\nexport interface TagCategory {\n name: string;\n description: string;\n examples: string[];\n}\n\nexport interface TagSchema {\n id: string;\n name: string;\n description: string;\n domain: 'legal' | 'scientific' | 'general';\n tags: TagCategory[];\n}\n\nexport const TAG_SCHEMAS: Record<string, TagSchema> = {\n 'legal-irac': {\n id: 'legal-irac',\n name: 'Legal Analysis (IRAC)',\n description: 'Issue, Rule, Application, Conclusion framework for legal reasoning',\n domain: 'legal',\n tags: [\n {\n name: 'Issue',\n description: 'The legal question or problem to be resolved',\n examples: [\n 'What is the central legal question?',\n 'What must the court decide?',\n 'What is the dispute about?'\n ]\n },\n {\n name: 'Rule',\n description: 'The relevant law, statute, or legal principle',\n examples: [\n 'What law applies?',\n 'What is the legal standard?',\n 'What statute governs this case?'\n ]\n },\n {\n name: 'Application',\n description: 'How the rule applies to the specific facts',\n examples: [\n 'How does the law apply to these facts?',\n 'Analysis of the case',\n 'How do the facts satisfy the legal standard?'\n ]\n },\n {\n name: 'Conclusion',\n description: 'The resolution or outcome based on the analysis',\n examples: [\n 'What is the court\\'s decision?',\n 'What is the final judgment?',\n 'What is the holding?'\n ]\n }\n ]\n },\n\n 'scientific-imrad': {\n id: 'scientific-imrad',\n name: 'Scientific Paper (IMRAD)',\n description: 'Introduction, Methods, Results, Discussion structure for research papers',\n domain: 'scientific',\n tags: [\n {\n name: 'Introduction',\n description: 'Background, context, and research question',\n examples: [\n 'What is the research question?',\n 'Why is this important?',\n 'What is the hypothesis?'\n ]\n },\n {\n name: 'Methods',\n description: 'Experimental design and procedures',\n examples: [\n 'How was the study conducted?',\n 'What methods were used?',\n 'What was the experimental design?'\n ]\n },\n {\n name: 'Results',\n description: 'Findings and observations',\n examples: [\n 'What did the study find?',\n 'What are the data?',\n 'What were the observations?'\n ]\n },\n {\n name: 'Discussion',\n description: 'Interpretation and implications of results',\n examples: [\n 'What do the results mean?',\n 'What are the implications?',\n 'How do these findings relate to prior work?'\n ]\n }\n ]\n },\n\n 'argument-toulmin': {\n id: 'argument-toulmin',\n name: 'Argument Structure (Toulmin)',\n description: 'Claim, Evidence, Warrant, Counterargument, Rebuttal framework for argumentation',\n domain: 'general',\n tags: [\n {\n name: 'Claim',\n description: 'The main assertion or thesis',\n examples: [\n 'What is being argued?',\n 'What is the main point?',\n 'What position is being taken?'\n ]\n },\n {\n name: 'Evidence',\n description: 'Data or facts supporting the claim',\n examples: [\n 'What supports this claim?',\n 'What are the facts?',\n 'What data is provided?'\n ]\n },\n {\n name: 'Warrant',\n description: 'Reasoning connecting evidence to claim',\n examples: [\n 'Why does this evidence support the claim?',\n 'What is the logic?',\n 'How does this reasoning work?'\n ]\n },\n {\n name: 'Counterargument',\n description: 'Opposing viewpoints or objections',\n examples: [\n 'What are the objections?',\n 'What do critics say?',\n 'What are alternative views?'\n ]\n },\n {\n name: 'Rebuttal',\n description: 'Response to counterarguments',\n examples: [\n 'How is the objection addressed?',\n 'Why is the counterargument wrong?',\n 'How is the criticism answered?'\n ]\n }\n ]\n }\n};\n\n/**\n * Get a tag schema by ID\n */\nexport function getTagSchema(schemaId: string): TagSchema | null {\n return TAG_SCHEMAS[schemaId] || null;\n}\n\n/**\n * Get all available tag schemas\n */\nexport function getAllTagSchemas(): TagSchema[] {\n return Object.values(TAG_SCHEMAS);\n}\n\n/**\n * Get tag schemas filtered by domain\n */\nexport function getTagSchemasByDomain(domain: 'legal' | 'scientific' | 'general'): TagSchema[] {\n return Object.values(TAG_SCHEMAS).filter(schema => schema.domain === domain);\n}\n\n/**\n * Validate that a category name is valid for a schema\n */\nexport function isValidCategory(schemaId: string, categoryName: string): boolean {\n const schema = getTagSchema(schemaId);\n if (!schema) return false;\n return schema.tags.some(tag => tag.name === categoryName);\n}\n\n/**\n * Get a specific category from a schema\n */\nexport function getSchemaCategory(schemaId: string, categoryName: string): TagCategory | null {\n const schema = getTagSchema(schemaId);\n if (!schema) return null;\n return schema.tags.find(tag => tag.name === categoryName) || null;\n}\n","/**\n * Entity Type Extraction Utilities\n *\n * Extract entity types from annotation bodies.\n * Entity types are stored as TextualBody with purpose: \"tagging\"\n */\n\n\nimport type { Annotation } from '@semiont/core';\n\n/**\n * Extract entity types from annotation bodies\n * Entity types are stored as TextualBody with purpose: \"tagging\"\n * Accepts any object with a body property matching Annotation['body'].\n * Body is optional (highlights carry none) — returns [] if absent.\n */\nexport function getEntityTypes(annotation: { body?: Annotation['body'] }): string[] {\n // Extract from TextualBody bodies with purpose: \"tagging\"\n if (Array.isArray(annotation.body)) {\n const entityTags: string[] = [];\n\n for (const item of annotation.body) {\n // Runtime check for TextualBody with tagging purpose\n // TypeScript incorrectly narrows the union type here, so we use runtime checks only\n if (\n typeof item === 'object' &&\n item !== null &&\n 'type' in item &&\n 'value' in item &&\n 'purpose' in item\n ) {\n // Access properties as unknown first to avoid TypeScript narrowing issues\n const itemType = (item as { type: unknown }).type;\n const itemValue = (item as { value: unknown }).value;\n const itemPurpose = (item as { purpose: unknown }).purpose;\n\n if (itemType === 'TextualBody' && itemPurpose === 'tagging' && typeof itemValue === 'string' && itemValue.length > 0) {\n entityTags.push(itemValue);\n }\n }\n }\n\n return entityTags;\n }\n\n return [];\n}\n","/**\n * Tag Schema Extraction Utilities\n *\n * Extract tag categories and schema IDs from tag annotations.\n * Tags use dual-body structure:\n * - First body has purpose: \"tagging\" with category value\n * - Second body has purpose: \"classifying\" with schema ID\n */\n\n\nimport type { Annotation } from '@semiont/core';\n\n/**\n * Type guard to check if an annotation is a tag\n */\nfunction isTag(annotation: Annotation): boolean {\n return annotation.motivation === 'tagging';\n}\n\n/**\n * Extract tag category from a tag annotation's body\n * Tags use dual-body structure: first body has purpose: \"tagging\" with category value\n * @param annotation - The annotation to extract category from\n * @returns The tag category (e.g., \"Issue\", \"Rule\"), or undefined if not a tag or no category found\n */\nexport function getTagCategory(annotation: Annotation): string | undefined {\n if (!isTag(annotation)) return undefined;\n const bodies = Array.isArray(annotation.body) ? annotation.body : [annotation.body];\n const taggingBody = bodies.find((b): b is Extract<typeof b, { purpose?: string }> =>\n b !== null && typeof b === 'object' && 'purpose' in b && b.purpose === 'tagging'\n );\n if (taggingBody && 'value' in taggingBody) {\n return taggingBody.value as string;\n }\n return undefined;\n}\n\n/**\n * Extract tag schema ID from a tag annotation's body\n * Tags use dual-body structure: second body has purpose: \"classifying\" with schema ID\n * @param annotation - The annotation to extract schema ID from\n * @returns The schema ID (e.g., \"legal-irac\"), or undefined if not a tag or no schema found\n */\nexport function getTagSchemaId(annotation: Annotation): string | undefined {\n if (!isTag(annotation)) return undefined;\n const bodies = Array.isArray(annotation.body) ? annotation.body : [annotation.body];\n const classifyingBody = bodies.find((b): b is Extract<typeof b, { purpose?: string }> =>\n b !== null && typeof b === 'object' && 'purpose' in b && b.purpose === 'classifying'\n );\n if (classifyingBody && 'value' in classifyingBody) {\n return classifyingBody.value as string;\n }\n return undefined;\n}\n"],"mappings":";AAMO,IAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;ACQO,IAAM,cAAyC;AAAA,EACpD,cAAc;AAAA,IACZ,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,aAAa;AAAA,IACb,QAAQ;AAAA,IACR,MAAM;AAAA,MACJ;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,QACb,UAAU;AAAA,UACR;AA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MACb;AAEA,cAAM,WAAY,KAA2B;AAC7C,cAAM,YAAa,KAA4B;AAC/C,cAAM,cAAe,KAA8B;AAEnD,YAAI,aAAa,iBAAiB,gBAAgB,aAAa,OAAO,cAAc,YAAY,UAAU,SAAS,GAAG;AACpH,qBAAW,KAAK,SAAS;AAAA,QAC3B;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAEA,SAAO,CAAC;AACV;;;AC/BA,SAAS,MAAM,YAAiC;AAC9C,SAAO,WAAW,eAAe;AACnC;AAQO,SAAS,eAAe,YAA4C;AACzE,MAAI,CAAC,MAAM,UAAU,EAAG,QAAO;AAC/B,QAAM,SAAS,MAAM,QAAQ,WAAW,IAAI,IAAI,WAAW,OAAO,CAAC,WAAW,IAAI;AAClF,QAAM,cAAc,OAAO;AAAA,IAAK,CAAC,MAC/B,MAAM,QAAQ,OAAO,MAAM,YAAY,aAAa,KAAK,EAAE,YAAY;AAAA,EACzE;AACA,MAAI,eAAe,WAAW,aAAa;AACzC,WAAO,YAAY;AAAA,EACrB;AACA,SAAO;AACT;AAQO,SAAS,eAAe,YAA4C;AACzE,MAAI,CAAC,MAAM,UAAU,EAAG,QAAO;AAC/B,QAAM,SAAS,MAAM,QAAQ,WAAW,IAAI,IAAI,WAAW,OAAO,CAAC,WAAW,IAAI;AAClF,QAAM,kBAAkB,OAAO;AAAA,IAAK,CAAC,MACnC,MAAM,QAAQ,OAAO,MAAM,YAAY,aAAa,KAAK,EAAE,YAAY;AAAA,EACzE;AACA,MAAI,mBAAmB,WAAW,iBAAiB;AACjD,WAAO,gBAAgB;AAAA,EACzB;AACA,SAAO;AACT;","names":[]}
1
+ {"version":3,"sources":["../src/entity-types.ts","../src/entity-extraction.ts","../src/tag-extraction.ts"],"sourcesContent":["/**\n * Default entity types for the Semiont system\n *\n * Entity types are used to tag resources and annotations with semantic categories.\n * These types serve as initial seed data for the entity types collection.\n */\nexport const DEFAULT_ENTITY_TYPES = [\n 'Person',\n 'Organization',\n 'Location',\n 'Event',\n 'Concept',\n 'Product',\n 'Technology',\n 'Date',\n 'Author'\n];\n","/**\n * Entity Type Extraction Utilities\n *\n * Extract entity types from annotation bodies.\n * Entity types are stored as TextualBody with purpose: \"tagging\"\n */\n\n\nimport type { Annotation } from '@semiont/core';\n\n/**\n * Extract entity types from annotation bodies\n * Entity types are stored as TextualBody with purpose: \"tagging\"\n * Accepts any object with a body property matching Annotation['body'].\n * Body is optional (highlights carry none) — returns [] if absent.\n */\nexport function getEntityTypes(annotation: { body?: Annotation['body'] }): string[] {\n // Extract from TextualBody bodies with purpose: \"tagging\"\n if (Array.isArray(annotation.body)) {\n const entityTags: string[] = [];\n\n for (const item of annotation.body) {\n // Runtime check for TextualBody with tagging purpose\n // TypeScript incorrectly narrows the union type here, so we use runtime checks only\n if (\n typeof item === 'object' &&\n item !== null &&\n 'type' in item &&\n 'value' in item &&\n 'purpose' in item\n ) {\n // Access properties as unknown first to avoid TypeScript narrowing issues\n const itemType = (item as { type: unknown }).type;\n const itemValue = (item as { value: unknown }).value;\n const itemPurpose = (item as { purpose: unknown }).purpose;\n\n if (itemType === 'TextualBody' && itemPurpose === 'tagging' && typeof itemValue === 'string' && itemValue.length > 0) {\n entityTags.push(itemValue);\n }\n }\n }\n\n return entityTags;\n }\n\n return [];\n}\n","/**\n * Tag Schema Extraction Utilities\n *\n * Extract tag categories and schema IDs from tag annotations.\n * Tags use dual-body structure:\n * - First body has purpose: \"tagging\" with category value\n * - Second body has purpose: \"classifying\" with schema ID\n */\n\n\nimport type { Annotation } from '@semiont/core';\n\n/**\n * Type guard to check if an annotation is a tag\n */\nfunction isTag(annotation: Annotation): boolean {\n return annotation.motivation === 'tagging';\n}\n\n/**\n * Extract tag category from a tag annotation's body\n * Tags use dual-body structure: first body has purpose: \"tagging\" with category value\n * @param annotation - The annotation to extract category from\n * @returns The tag category (e.g., \"Issue\", \"Rule\"), or undefined if not a tag or no category found\n */\nexport function getTagCategory(annotation: Annotation): string | undefined {\n if (!isTag(annotation)) return undefined;\n const bodies = Array.isArray(annotation.body) ? annotation.body : [annotation.body];\n const taggingBody = bodies.find((b): b is Extract<typeof b, { purpose?: string }> =>\n b !== null && typeof b === 'object' && 'purpose' in b && b.purpose === 'tagging'\n );\n if (taggingBody && 'value' in taggingBody) {\n return taggingBody.value as string;\n }\n return undefined;\n}\n\n/**\n * Extract tag schema ID from a tag annotation's body\n * Tags use dual-body structure: second body has purpose: \"classifying\" with schema ID\n * @param annotation - The annotation to extract schema ID from\n * @returns The schema ID (e.g., \"legal-irac\"), or undefined if not a tag or no schema found\n */\nexport function getTagSchemaId(annotation: Annotation): string | undefined {\n if (!isTag(annotation)) return undefined;\n const bodies = Array.isArray(annotation.body) ? annotation.body : [annotation.body];\n const classifyingBody = bodies.find((b): b is Extract<typeof b, { purpose?: string }> =>\n b !== null && typeof b === 'object' && 'purpose' in b && b.purpose === 'classifying'\n );\n if (classifyingBody && 'value' in classifyingBody) {\n return classifyingBody.value as string;\n }\n return undefined;\n}\n"],"mappings":";AAMO,IAAM,uBAAuB;AAAA,EAClC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;;;ACAO,SAAS,eAAe,YAAqD;AAElF,MAAI,MAAM,QAAQ,WAAW,IAAI,GAAG;AAClC,UAAM,aAAuB,CAAC;AAE9B,eAAW,QAAQ,WAAW,MAAM;AAGlC,UACE,OAAO,SAAS,YAChB,SAAS,QACT,UAAU,QACV,WAAW,QACX,aAAa,MACb;AAEA,cAAM,WAAY,KAA2B;AAC7C,cAAM,YAAa,KAA4B;AAC/C,cAAM,cAAe,KAA8B;AAEnD,YAAI,aAAa,iBAAiB,gBAAgB,aAAa,OAAO,cAAc,YAAY,UAAU,SAAS,GAAG;AACpH,qBAAW,KAAK,SAAS;AAAA,QAC3B;AAAA,MACF;AAAA,IACF;AAEA,WAAO;AAAA,EACT;AAEA,SAAO,CAAC;AACV;;;AC/BA,SAAS,MAAM,YAAiC;AAC9C,SAAO,WAAW,eAAe;AACnC;AAQO,SAAS,eAAe,YAA4C;AACzE,MAAI,CAAC,MAAM,UAAU,EAAG,QAAO;AAC/B,QAAM,SAAS,MAAM,QAAQ,WAAW,IAAI,IAAI,WAAW,OAAO,CAAC,WAAW,IAAI;AAClF,QAAM,cAAc,OAAO;AAAA,IAAK,CAAC,MAC/B,MAAM,QAAQ,OAAO,MAAM,YAAY,aAAa,KAAK,EAAE,YAAY;AAAA,EACzE;AACA,MAAI,eAAe,WAAW,aAAa;AACzC,WAAO,YAAY;AAAA,EACrB;AACA,SAAO;AACT;AAQO,SAAS,eAAe,YAA4C;AACzE,MAAI,CAAC,MAAM,UAAU,EAAG,QAAO;AAC/B,QAAM,SAAS,MAAM,QAAQ,WAAW,IAAI,IAAI,WAAW,OAAO,CAAC,WAAW,IAAI;AAClF,QAAM,kBAAkB,OAAO;AAAA,IAAK,CAAC,MACnC,MAAM,QAAQ,OAAO,MAAM,YAAY,aAAa,KAAK,EAAE,YAAY;AAAA,EACzE;AACA,MAAI,mBAAmB,WAAW,iBAAiB;AACjD,WAAO,gBAAgB;AAAA,EACzB;AACA,SAAO;AACT;","names":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@semiont/ontology",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "type": "module",
5
5
  "description": "Entity types, tag schemas, and W3C annotation vocabularies",
6
6
  "main": "./dist/index.js",