@semiont/ontology 0.5.2 → 0.5.4
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 +18 -57
- package/dist/bootstrap.d.ts +12 -0
- package/dist/bootstrap.d.ts.map +1 -0
- package/dist/entity-extraction.d.ts +17 -0
- package/dist/entity-extraction.d.ts.map +1 -0
- package/dist/entity-types.d.ts +8 -0
- package/dist/entity-types.d.ts.map +1 -0
- package/dist/index.d.ts +13 -128
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +1 -171
- package/dist/index.js.map +1 -1
- package/dist/tag-collections.d.ts +36 -0
- package/dist/tag-collections.d.ts.map +1 -0
- package/dist/tag-extraction.d.ts +24 -0
- package/dist/tag-extraction.d.ts.map +1 -0
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -6,14 +6,15 @@
|
|
|
6
6
|
[](https://www.npmjs.com/package/@semiont/ontology)
|
|
7
7
|
[](https://github.com/The-AI-Alliance/semiont/blob/main/LICENSE)
|
|
8
8
|
|
|
9
|
-
Entity types
|
|
9
|
+
Entity types and annotation-body extraction utilities for the Semiont annotation system.
|
|
10
10
|
|
|
11
11
|
## Overview
|
|
12
12
|
|
|
13
|
-
This package
|
|
14
|
-
- **Entity types**: Semantic categories for tagging resources and annotations (Person, Organization, Location, etc.)
|
|
15
|
-
- **Tag
|
|
16
|
-
|
|
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
|
-
|
|
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
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
-
│
|
|
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
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entity Types Bootstrap - moved to backend
|
|
3
|
+
*
|
|
4
|
+
* NOTE: The bootstrap service has been moved back to apps/backend/src/bootstrap/entity-types-bootstrap.ts
|
|
5
|
+
* to avoid circular dependency between @semiont/ontology and @semiont/core.
|
|
6
|
+
*
|
|
7
|
+
* Only DEFAULT_ENTITY_TYPES is exported from this package.
|
|
8
|
+
* The bootstrap logic depends on EnvironmentConfig from @semiont/core and EventStore from backend,
|
|
9
|
+
* so it belongs in the backend, not in the ontology package.
|
|
10
|
+
*/
|
|
11
|
+
export { DEFAULT_ENTITY_TYPES } from './entity-types';
|
|
12
|
+
//# sourceMappingURL=bootstrap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bootstrap.d.ts","sourceRoot":"","sources":["../src/bootstrap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Entity Type Extraction Utilities
|
|
3
|
+
*
|
|
4
|
+
* Extract entity types from annotation bodies.
|
|
5
|
+
* Entity types are stored as TextualBody with purpose: "tagging"
|
|
6
|
+
*/
|
|
7
|
+
import type { Annotation } from '@semiont/core';
|
|
8
|
+
/**
|
|
9
|
+
* Extract entity types from annotation bodies
|
|
10
|
+
* Entity types are stored as TextualBody with purpose: "tagging"
|
|
11
|
+
* Accepts any object with a body property matching Annotation['body'].
|
|
12
|
+
* Body is optional (highlights carry none) — returns [] if absent.
|
|
13
|
+
*/
|
|
14
|
+
export declare function getEntityTypes(annotation: {
|
|
15
|
+
body?: Annotation['body'];
|
|
16
|
+
}): string[];
|
|
17
|
+
//# sourceMappingURL=entity-extraction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-extraction.d.ts","sourceRoot":"","sources":["../src/entity-extraction.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAEhD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE;IAAE,IAAI,CAAC,EAAE,UAAU,CAAC,MAAM,CAAC,CAAA;CAAE,GAAG,MAAM,EAAE,CA8BlF"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Default entity types for the Semiont system
|
|
3
|
+
*
|
|
4
|
+
* Entity types are used to tag resources and annotations with semantic categories.
|
|
5
|
+
* These types serve as initial seed data for the entity types collection.
|
|
6
|
+
*/
|
|
7
|
+
export declare const DEFAULT_ENTITY_TYPES: string[];
|
|
8
|
+
//# sourceMappingURL=entity-types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"entity-types.d.ts","sourceRoot":"","sources":["../src/entity-types.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,eAAO,MAAM,oBAAoB,UAUhC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,131 +1,16 @@
|
|
|
1
|
-
import { Annotation } from '@semiont/core';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
|
-
*
|
|
2
|
+
* @semiont/ontology
|
|
5
3
|
*
|
|
6
|
-
* Entity
|
|
7
|
-
* These types serve as initial seed data for the entity types collection.
|
|
8
|
-
*/
|
|
9
|
-
declare const DEFAULT_ENTITY_TYPES: string[];
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Tag Collections Management
|
|
13
|
-
*
|
|
14
|
-
* Stores entity types in the graph database as append-only collections.
|
|
15
|
-
* Provides interface for graph database implementations to manage entity type collections.
|
|
16
|
-
*/
|
|
17
|
-
interface TagCollection {
|
|
18
|
-
id: string;
|
|
19
|
-
collectionType: 'entity-types';
|
|
20
|
-
tags: string[];
|
|
21
|
-
created: Date;
|
|
22
|
-
updatedAt: Date;
|
|
23
|
-
}
|
|
24
|
-
interface TagCollectionOperations {
|
|
25
|
-
/**
|
|
26
|
-
* Get or create collections with auto-seeding
|
|
27
|
-
*/
|
|
28
|
-
getEntityTypes(): Promise<string[]>;
|
|
29
|
-
/**
|
|
30
|
-
* Append new tag (no duplicates)
|
|
31
|
-
*/
|
|
32
|
-
addEntityType(tag: string): Promise<void>;
|
|
33
|
-
/**
|
|
34
|
-
* Bulk append tags
|
|
35
|
-
*/
|
|
36
|
-
addEntityTypes(tags: string[]): Promise<void>;
|
|
37
|
-
/**
|
|
38
|
-
* Check if collections exist
|
|
39
|
-
*/
|
|
40
|
-
hasEntityTypesCollection(): Promise<boolean>;
|
|
41
|
-
/**
|
|
42
|
-
* Initialize collections with seed data if they don't exist
|
|
43
|
-
*/
|
|
44
|
-
initializeCollections(): Promise<void>;
|
|
45
|
-
}
|
|
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).
|
|
4
|
+
* Entity-type vocabulary + annotation-body extraction utilities.
|
|
53
5
|
*
|
|
54
|
-
*
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
/**
|
|
91
|
-
* Entity Type Extraction Utilities
|
|
92
|
-
*
|
|
93
|
-
* Extract entity types from annotation bodies.
|
|
94
|
-
* Entity types are stored as TextualBody with purpose: "tagging"
|
|
95
|
-
*/
|
|
96
|
-
|
|
97
|
-
/**
|
|
98
|
-
* Extract entity types from annotation bodies
|
|
99
|
-
* Entity types are stored as TextualBody with purpose: "tagging"
|
|
100
|
-
* Accepts any object with a body property matching Annotation['body'].
|
|
101
|
-
* Body is optional (highlights carry none) — returns [] if absent.
|
|
102
|
-
*/
|
|
103
|
-
declare function getEntityTypes(annotation: {
|
|
104
|
-
body?: Annotation['body'];
|
|
105
|
-
}): string[];
|
|
106
|
-
|
|
107
|
-
/**
|
|
108
|
-
* Tag Schema Extraction Utilities
|
|
109
|
-
*
|
|
110
|
-
* Extract tag categories and schema IDs from tag annotations.
|
|
111
|
-
* Tags use dual-body structure:
|
|
112
|
-
* - First body has purpose: "tagging" with category value
|
|
113
|
-
* - Second body has purpose: "classifying" with schema ID
|
|
114
|
-
*/
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Extract tag category from a tag annotation's body
|
|
118
|
-
* Tags use dual-body structure: first body has purpose: "tagging" with category value
|
|
119
|
-
* @param annotation - The annotation to extract category from
|
|
120
|
-
* @returns The tag category (e.g., "Issue", "Rule"), or undefined if not a tag or no category found
|
|
121
|
-
*/
|
|
122
|
-
declare function getTagCategory(annotation: Annotation): string | undefined;
|
|
123
|
-
/**
|
|
124
|
-
* Extract tag schema ID from a tag annotation's body
|
|
125
|
-
* Tags use dual-body structure: second body has purpose: "classifying" with schema ID
|
|
126
|
-
* @param annotation - The annotation to extract schema ID from
|
|
127
|
-
* @returns The schema ID (e.g., "legal-irac"), or undefined if not a tag or no schema found
|
|
128
|
-
*/
|
|
129
|
-
declare function getTagSchemaId(annotation: Annotation): string | undefined;
|
|
130
|
-
|
|
131
|
-
export { DEFAULT_ENTITY_TYPES, TAG_SCHEMAS, type TagCategory, type TagCollection, type TagCollectionOperations, type TagSchema, getAllTagSchemas, getEntityTypes, getSchemaCategory, getTagCategory, getTagSchema, getTagSchemaId, getTagSchemasByDomain, isValidCategory };
|
|
6
|
+
* Note: tag-schema *data* lives with the KB that owns it (registered at
|
|
7
|
+
* runtime via `frame.addTagSchema(...)`). The `TagSchema` and `TagCategory`
|
|
8
|
+
* *types* are exported from `@semiont/core`. This package owns only the
|
|
9
|
+
* extraction helpers (`getTagCategory`, `getTagSchemaId`) that read schema
|
|
10
|
+
* provenance off an annotation's body.
|
|
11
|
+
*/
|
|
12
|
+
export { DEFAULT_ENTITY_TYPES } from './entity-types';
|
|
13
|
+
export type { TagCollection, TagCollectionOperations } from './tag-collections';
|
|
14
|
+
export { getEntityTypes } from './entity-extraction';
|
|
15
|
+
export { getTagCategory, getTagSchemaId } from './tag-extraction';
|
|
16
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAGtD,YAAY,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,mBAAmB,CAAC;AAGhF,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAGrD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC"}
|
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
|
-
|
|
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;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,QACb,UAAU;AAAA,UACR;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,QACb,UAAU;AAAA,UACR;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,QACb,UAAU;AAAA,UACR;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,oBAAoB;AAAA,IAClB,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;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,QACb,UAAU;AAAA,UACR;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,QACb,UAAU;AAAA,UACR;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,QACb,UAAU;AAAA,UACR;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAAA,EAEA,oBAAoB;AAAA,IAClB,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;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,QACb,UAAU;AAAA,UACR;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,QACb,UAAU;AAAA,UACR;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,QACb,UAAU;AAAA,UACR;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,MACA;AAAA,QACE,MAAM;AAAA,QACN,aAAa;AAAA,QACb,UAAU;AAAA,UACR;AAAA,UACA;AAAA,UACA;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF;AAKO,SAAS,aAAa,UAAoC;AAC/D,SAAO,YAAY,QAAQ,KAAK;AAClC;AAKO,SAAS,mBAAgC;AAC9C,SAAO,OAAO,OAAO,WAAW;AAClC;AAKO,SAAS,sBAAsB,QAAyD;AAC7F,SAAO,OAAO,OAAO,WAAW,EAAE,OAAO,YAAU,OAAO,WAAW,MAAM;AAC7E;AAKO,SAAS,gBAAgB,UAAkB,cAA+B;AAC/E,QAAM,SAAS,aAAa,QAAQ;AACpC,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,OAAO,KAAK,KAAK,SAAO,IAAI,SAAS,YAAY;AAC1D;AAKO,SAAS,kBAAkB,UAAkB,cAA0C;AAC5F,QAAM,SAAS,aAAa,QAAQ;AACpC,MAAI,CAAC,OAAQ,QAAO;AACpB,SAAO,OAAO,KAAK,KAAK,SAAO,IAAI,SAAS,YAAY,KAAK;AAC/D;;;AC/LO,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":[]}
|
|
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":[]}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tag Collections Management
|
|
3
|
+
*
|
|
4
|
+
* Stores entity types in the graph database as append-only collections.
|
|
5
|
+
* Provides interface for graph database implementations to manage entity type collections.
|
|
6
|
+
*/
|
|
7
|
+
export interface TagCollection {
|
|
8
|
+
id: string;
|
|
9
|
+
collectionType: 'entity-types';
|
|
10
|
+
tags: string[];
|
|
11
|
+
created: Date;
|
|
12
|
+
updatedAt: Date;
|
|
13
|
+
}
|
|
14
|
+
export interface TagCollectionOperations {
|
|
15
|
+
/**
|
|
16
|
+
* Get or create collections with auto-seeding
|
|
17
|
+
*/
|
|
18
|
+
getEntityTypes(): Promise<string[]>;
|
|
19
|
+
/**
|
|
20
|
+
* Append new tag (no duplicates)
|
|
21
|
+
*/
|
|
22
|
+
addEntityType(tag: string): Promise<void>;
|
|
23
|
+
/**
|
|
24
|
+
* Bulk append tags
|
|
25
|
+
*/
|
|
26
|
+
addEntityTypes(tags: string[]): Promise<void>;
|
|
27
|
+
/**
|
|
28
|
+
* Check if collections exist
|
|
29
|
+
*/
|
|
30
|
+
hasEntityTypesCollection(): Promise<boolean>;
|
|
31
|
+
/**
|
|
32
|
+
* Initialize collections with seed data if they don't exist
|
|
33
|
+
*/
|
|
34
|
+
initializeCollections(): Promise<void>;
|
|
35
|
+
}
|
|
36
|
+
//# sourceMappingURL=tag-collections.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag-collections.d.ts","sourceRoot":"","sources":["../src/tag-collections.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,MAAM,WAAW,aAAa;IAC5B,EAAE,EAAE,MAAM,CAAC;IACX,cAAc,EAAE,cAAc,CAAC;IAC/B,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,OAAO,EAAE,IAAI,CAAC;IACd,SAAS,EAAE,IAAI,CAAC;CACjB;AAED,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,cAAc,IAAI,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAEpC;;OAEG;IACH,aAAa,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1C;;OAEG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAE9C;;OAEG;IACH,wBAAwB,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC;IAE7C;;OAEG;IACH,qBAAqB,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACxC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tag Schema Extraction Utilities
|
|
3
|
+
*
|
|
4
|
+
* Extract tag categories and schema IDs from tag annotations.
|
|
5
|
+
* Tags use dual-body structure:
|
|
6
|
+
* - First body has purpose: "tagging" with category value
|
|
7
|
+
* - Second body has purpose: "classifying" with schema ID
|
|
8
|
+
*/
|
|
9
|
+
import type { Annotation } from '@semiont/core';
|
|
10
|
+
/**
|
|
11
|
+
* Extract tag category from a tag annotation's body
|
|
12
|
+
* Tags use dual-body structure: first body has purpose: "tagging" with category value
|
|
13
|
+
* @param annotation - The annotation to extract category from
|
|
14
|
+
* @returns The tag category (e.g., "Issue", "Rule"), or undefined if not a tag or no category found
|
|
15
|
+
*/
|
|
16
|
+
export declare function getTagCategory(annotation: Annotation): string | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Extract tag schema ID from a tag annotation's body
|
|
19
|
+
* Tags use dual-body structure: second body has purpose: "classifying" with schema ID
|
|
20
|
+
* @param annotation - The annotation to extract schema ID from
|
|
21
|
+
* @returns The schema ID (e.g., "legal-irac"), or undefined if not a tag or no schema found
|
|
22
|
+
*/
|
|
23
|
+
export declare function getTagSchemaId(annotation: Annotation): string | undefined;
|
|
24
|
+
//# sourceMappingURL=tag-extraction.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tag-extraction.d.ts","sourceRoot":"","sources":["../src/tag-extraction.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAShD;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAUzE;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAAC,UAAU,EAAE,UAAU,GAAG,MAAM,GAAG,SAAS,CAUzE"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@semiont/ontology",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Entity types, tag schemas, and W3C annotation vocabularies",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -16,7 +16,7 @@
|
|
|
16
16
|
"README.md"
|
|
17
17
|
],
|
|
18
18
|
"scripts": {
|
|
19
|
-
"build": "npm run typecheck && tsup",
|
|
19
|
+
"build": "npm run typecheck && tsup && tsc -p tsconfig.build.json",
|
|
20
20
|
"typecheck": "tsc --noEmit",
|
|
21
21
|
"clean": "rm -rf dist",
|
|
22
22
|
"test": "vitest run",
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"devDependencies": {
|
|
28
28
|
"@vitest/coverage-v8": "^4.1.0",
|
|
29
29
|
"tsup": "^8.0.1",
|
|
30
|
-
"typescript": "^
|
|
30
|
+
"typescript": "^6.0.2"
|
|
31
31
|
},
|
|
32
32
|
"publishConfig": {
|
|
33
33
|
"access": "public"
|