mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-01 09:29:38 +02:00
Normalize term translation with Effect Match
This commit is contained in:
parent
e311315556
commit
09d34fb4d4
11 changed files with 349 additions and 190 deletions
|
|
@ -6,6 +6,7 @@ import {
|
|||
GraphRagResponse,
|
||||
Term,
|
||||
TextCompletionRequest,
|
||||
Triple,
|
||||
loadProcessorRuntimeConfig,
|
||||
} from "../index.js";
|
||||
|
||||
|
|
@ -40,6 +41,20 @@ describe("Effect schemas", () => {
|
|||
}),
|
||||
);
|
||||
|
||||
it.effect(
|
||||
"decode triples with named graph strings",
|
||||
Effect.fnUntraced(function* () {
|
||||
const triple = yield* S.decodeUnknownEffect(Triple)({
|
||||
s: { type: "IRI", iri: "urn:s" },
|
||||
p: { type: "IRI", iri: "urn:p" },
|
||||
o: { type: "LITERAL", value: "object" },
|
||||
g: "urn:graph",
|
||||
});
|
||||
|
||||
expect(triple.g).toBe("urn:graph");
|
||||
}),
|
||||
);
|
||||
|
||||
it.effect(
|
||||
"preserve gateway response extension fields",
|
||||
Effect.fnUntraced(function* () {
|
||||
|
|
|
|||
|
|
@ -45,30 +45,28 @@ export type Triple = {
|
|||
readonly s: Term;
|
||||
readonly p: Term;
|
||||
readonly o: Term;
|
||||
readonly g?: Term;
|
||||
readonly g?: string;
|
||||
};
|
||||
|
||||
export const Triple: S.Codec<Triple, Triple> = S.suspend(() =>
|
||||
S.Struct({
|
||||
s: Term,
|
||||
p: Term,
|
||||
o: Term,
|
||||
g: S.optionalKey(Term),
|
||||
})
|
||||
);
|
||||
export const Triple: S.Codec<Triple, Triple> = S.Struct({
|
||||
s: S.suspend((): S.Codec<Term, Term> => Term),
|
||||
p: S.suspend((): S.Codec<Term, Term> => Term),
|
||||
o: S.suspend((): S.Codec<Term, Term> => Term),
|
||||
g: S.optionalKey(S.String),
|
||||
});
|
||||
|
||||
export const TripleTerm: S.Codec<TripleTerm, TripleTerm> = S.suspend(() =>
|
||||
S.Struct({
|
||||
type: S.tag("TRIPLE"),
|
||||
triple: Triple,
|
||||
})
|
||||
);
|
||||
export const TripleTerm: S.Codec<TripleTerm, TripleTerm> = S.Struct({
|
||||
type: S.tag("TRIPLE"),
|
||||
triple: S.suspend((): S.Codec<Triple, Triple> => Triple),
|
||||
});
|
||||
export interface TripleTerm {
|
||||
readonly type: "TRIPLE";
|
||||
readonly triple: Triple;
|
||||
}
|
||||
|
||||
export const Term: S.Codec<Term, Term> = S.suspend(() => S.Union([IriTerm, BlankTerm, LiteralTerm, TripleTerm]));
|
||||
export const Term = S.Union([IriTerm, BlankTerm, LiteralTerm, TripleTerm]).pipe(
|
||||
S.toTaggedUnion("type"),
|
||||
);
|
||||
|
||||
export const Field = S.Struct({
|
||||
name: S.String,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue