mirror of
https://github.com/trustgraph-ai/trustgraph.git
synced 2026-07-01 17:39:39 +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
|
|
@ -9,7 +9,7 @@
|
|||
*/
|
||||
|
||||
import { errorMessage, type Term } from "@trustgraph/base";
|
||||
import { Config, Context, Effect, Layer, Random } from "effect";
|
||||
import { Config, Context, Effect, Layer, Match, Random } from "effect";
|
||||
import * as O from "effect/Option";
|
||||
import * as S from "effect/Schema";
|
||||
import { makeQdrantClient, type QdrantClientFactory, type QdrantClientLike } from "../../qdrant/client.js";
|
||||
|
|
@ -84,16 +84,14 @@ const randomPointId = Effect.fn("QdrantGraphEmbeddings.randomPointId")(function*
|
|||
});
|
||||
|
||||
function getTermValue(term: Term): string | null {
|
||||
switch (term.type) {
|
||||
case "IRI":
|
||||
return term.iri;
|
||||
case "LITERAL":
|
||||
return term.value;
|
||||
case "BLANK":
|
||||
return term.id;
|
||||
case "TRIPLE":
|
||||
return null;
|
||||
}
|
||||
return Match.type<Term>().pipe(
|
||||
Match.discriminatorsExhaustive("type")({
|
||||
IRI: (iri) => iri.iri,
|
||||
LITERAL: (literal) => literal.value,
|
||||
BLANK: (blank) => blank.id,
|
||||
TRIPLE: () => null,
|
||||
}),
|
||||
)(term);
|
||||
}
|
||||
|
||||
export interface QdrantGraphEmbeddingsStore {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
import { createClient, Graph } from "falkordb";
|
||||
import { errorMessage, type Term, type Triple } from "@trustgraph/base";
|
||||
import { Config, Context, Effect, Layer } from "effect";
|
||||
import { Config, Context, Effect, Layer, Match } from "effect";
|
||||
import * as S from "effect/Schema";
|
||||
|
||||
export interface FalkorDBClosableClient {
|
||||
|
|
@ -40,16 +40,14 @@ export interface FalkorDBConfig {
|
|||
}
|
||||
|
||||
function getTermValue(term: Term): string {
|
||||
switch (term.type) {
|
||||
case "IRI":
|
||||
return term.iri;
|
||||
case "LITERAL":
|
||||
return term.value;
|
||||
case "BLANK":
|
||||
return term.id;
|
||||
case "TRIPLE":
|
||||
return getTermValue(term.triple.s);
|
||||
}
|
||||
return Match.type<Term>().pipe(
|
||||
Match.discriminatorsExhaustive("type")({
|
||||
IRI: (iri) => iri.iri,
|
||||
LITERAL: (literal) => literal.value,
|
||||
BLANK: (blank) => blank.id,
|
||||
TRIPLE: (triple) => getTermValue(triple.triple.s),
|
||||
}),
|
||||
)(term);
|
||||
}
|
||||
|
||||
export interface FalkorDBTriplesStore {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue