• Extracts data from an RDF graph according to a JSON Schema

    This is the main entry point for the new extractor implementation. It automatically normalizes the schema if needed, then uses the normalized schema structure to guide extraction from the graph.

    Key improvements over the legacy implementation:

    • Uses normalized schemas (no ref resolution during extraction)
    • Cleaner separation of concerns with dedicated extractor functions
    • Better handling of anyOf/oneOf patterns
    • Structured logging support
    • Depth control via schema structure (no infinite loops)

    Type Parameters

    • T = any

      The type to derive filter patterns from (typically z.infer)

    Parameters

    • iri: string

      The IRI of the entity to extract

    • dataset: DatasetCore

      The RDF dataset to extract from

    • schema: JSONSchema7

      The JSON Schema defining the structure to extract

    • options: Partial<ExtendedWalkerOptions<T>> = {}

      Walker options including filter options (select/include/omit)

    • baseIRI: string = "http://schema.org/"

      Optional base IRI for expanding property names (defaults to "http://schema.org/")

    • Optionalcontext: Record<string, string>

      Optional prefix mappings for property name expansion

    • Optionallogger: Logger

      Optional logger for debugging (defaults to no-op)

    Returns any

    The extracted data as a JavaScript object

    // Without type parameter (backward compatible)
    const result = extractFromGraph(
    "http://example.com/person1",
    dataset,
    personSchema,
    {
    includeRelationsByDefault: false,
    include: { friends: { take: 10 } },
    omit: ["internalId"],
    },
    "http://schema.org/",
    { dc: "http://purl.org/dc/elements/1.1/" }
    );

    // With Zod type inference for type safety
    import { z } from 'zod';
    const zodSchema = z.object({
    name: z.string(),
    friends: z.array(z.object({ name: z.string() }))
    });
    type Person = z.infer<typeof zodSchema>;

    const result2 = extractFromGraph<Person>(
    "http://example.com/person1",
    dataset,
    personSchema,
    {
    include: { friends: { take: 10 } } // Type-safe: only valid keys allowed
    }
    );