mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-03 15:01:00 +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
|
|
@ -21,7 +21,7 @@ import type {
|
|||
TriplesQueryResponse,
|
||||
} from "@trustgraph/base";
|
||||
import { errorMessage } from "@trustgraph/base";
|
||||
import { Context, Effect, Layer } from "effect";
|
||||
import { Context, Effect, Layer, Match } from "effect";
|
||||
import * as O from "effect/Option";
|
||||
import * as S from "effect/Schema";
|
||||
|
||||
|
|
@ -461,16 +461,15 @@ function parseScoredEdges(responseText: string): Array<typeof ScoredEdge.Type> {
|
|||
}
|
||||
|
||||
export function termToString(term: Term): string {
|
||||
switch (term.type) {
|
||||
case "IRI":
|
||||
return term.iri;
|
||||
case "LITERAL":
|
||||
return term.value;
|
||||
case "BLANK":
|
||||
return `_:${term.id}`;
|
||||
case "TRIPLE":
|
||||
return `(${termToString(term.triple.s)} ${termToString(term.triple.p)} ${termToString(term.triple.o)})`;
|
||||
}
|
||||
return Match.type<Term>().pipe(
|
||||
Match.discriminatorsExhaustive("type")({
|
||||
IRI: (iri) => iri.iri,
|
||||
LITERAL: (literal) => literal.value,
|
||||
BLANK: (blank) => `_:${blank.id}`,
|
||||
TRIPLE: (triple) =>
|
||||
`(${termToString(triple.triple.s)} ${termToString(triple.triple.p)} ${termToString(triple.triple.o)})`,
|
||||
}),
|
||||
)(term);
|
||||
}
|
||||
|
||||
export function stringToTerm(value: string): Term {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue