### Building and Deploying the Project (Makefile) Source: https://github.com/fluree/json-ld/blob/main/README.md Outlines the make commands for building the project's artifacts, including deployable JARs and JavaScript ESM modules, as well as installing and deploying the library. ```bash $ make jar $ make js-package # Build both Node.js and browser modules $ make all # Build both JAR and JavaScript modules $ make install $ make deploy # Deploy to Clojars (requires CLOJARS_USERNAME and CLOJARS_PASSWORD environment variables) ``` -------------------------------- ### Install @fluree/json-ld for JavaScript/npm Source: https://context7.com/fluree/json-ld/llms.txt Install the @fluree/json-ld package using npm for use in your JavaScript or Node.js projects. This command fetches and installs the library and its dependencies. ```bash npm install @fluree/json-ld ``` -------------------------------- ### Manual Testing of Fluree JSON-LD Functions Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md Example of how to manually test individual Fluree JSON-LD functions from the Clojure REPL. This allows for quick verification of functions like `parse-context` and `expand-iri`. ```clojure ;; Test individual functions manually clojure -M:dev:test -e " (require 'fluree.json-ld) (def ctx (fluree.json-ld/parse-context {"name" "http://schema.org/name"})) (println "Context parsed:" ctx) (println "IRI expanded:" (fluree.json-ld/expand-iri "name" ctx)) " ``` -------------------------------- ### Configure Native Image Build for Fluree JSON-LD Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md This command adds the necessary feature and reflection configuration file for building a GraalVM native image that includes Fluree JSON-LD. Ensure you have the `clj_easy.graal_build_time` feature installed and the `graalvm/reflect-config.json` file present. ```bash native-image \ --features=clj_easy.graal_build_time.InitClojureClasses \ -H:ReflectionConfigurationFiles=graalvm/reflect-config.json \ # ... your other flags ``` -------------------------------- ### Install fluree/json-ld Dependency Source: https://github.com/fluree/json-ld/blob/main/README.md Add the fluree/json-ld library as a dependency to your Clojure project by including the provided Maven coordinates in your `deps.edn` file. This makes the library's functions available for use in your project. ```clojure com.fluree/json-ld {:mvn/version "0.1.0"} ``` -------------------------------- ### Add GraalVM Dependencies to Clojure Project Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md Configures a Clojure project's `deps.edn` file to include the fluree/json-ld library and the `graal-build-time` dependency for GraalVM native image support. This setup is necessary for projects that depend on fluree/json-ld and aim for native compilation. ```clojure ;; In your deps.edn {:deps {com.fluree/json-ld {:mvn/version "LATEST"}} :aliases {:graalvm {:extra-deps {com.github.clj-easy/graal-build-time {:mvn/version "1.0.5"}}}}} ``` -------------------------------- ### Get External IRI Information (Clojure) Source: https://context7.com/fluree/json-ld/llms.txt Retrieves IRI information for a given IRI from pre-loaded vocabularies. Returns nil if the IRI is not found. Requires the 'fluree.json-ld' namespace. ```clojure (require '[fluree.json-ld :as json-ld]) ;; Get IRI info for Schema.org term (json-ld/external-iri "http://schema.org/name") ;; => Returns IRI information if available ;; Non-existent IRI returns nil (json-ld/external-iri "http://example.com/nonexistent") ;; => nil ``` -------------------------------- ### JavaScript/ESM API Usage for JSON-LD Source: https://github.com/fluree/json-ld/blob/main/README.md Provides examples of using the JavaScript/ESM API for the Fluree JSON-LD library in both Node.js and browser environments. It covers importing functions, detecting JSON-LD, parsing contexts, expanding documents, normalizing data, and performing a full workflow. ```javascript // Node.js import { expand, compact, normalizeData, parseContext, jsonLd } from '@fluree/json-ld'; // Browser import { expand, compact, normalizeData, parseContext, jsonLd } from './dist/browser/fluree-json-ld.js'; // Works with plain JavaScript objects const doc = { "@context": { "name": "http://schema.org/name" }, "@type": "Person", "name": "John Doe" }; // JSON-LD detection const isJsonLd = jsonLd(doc); // true // Parse context (returns internal format for other functions) const context = parseContext(doc["@context"]); // Expand document const expanded = expand(doc); // Normalize for hashing/comparison const normalized = normalizeData(doc); // Returns string // Full workflow const parsedContext = parseContext({ "name": "http://schema.org/name" }); const expandedDoc = expand(doc); const compactedIri = compact(expandedDoc, parsedContext); ``` -------------------------------- ### Get JSON-LD Expansion Details (Clojure) Source: https://github.com/fluree/json-ld/blob/main/README.md Retrieve details about IRI expansion, including the fully expanded IRI and associated context settings. This function allows control over whether vocabulary terms are expanded or treated as literal @id values. ```clojure (require '[fluree.json-ld :as json-ld]) ;; Get expansion details including context settings ;; (json-ld/details "schema:name" parsed-context) ;; => ["http://schema.org/name" {:id "schema:name", ...}] ;; Control vocabulary expansion ;; (json-ld/details "myapp:userId" parsed-context false) ;; => Expands as @id rather than vocabulary term ``` -------------------------------- ### Compare JVM vs. Native Image Startup Times (Bash) Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md This snippet demonstrates how to compare the startup performance of a Java application running on the JVM versus a native image compiled with GraalVM. It first builds the native image and then uses the `time` command to measure the execution duration for both versions. Ensure `your-app.jar` and `your-app-native` are correctly named and located. ```bash # Test native image performance vs JVM # Build native image first ./graalvm/configs/native-image.sh # Compare startup times time java -jar target/your-app.jar # JVM version time ./your-app-native # Native version ``` -------------------------------- ### Optimize Memory and Enable Build-Time Initialization Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md Configuration tips for GraalVM native image optimization. This includes increasing the JVM heap size for large JSON-LD contexts and enabling class initialization at build time for the `fluree.json_ld` package. ```bash # For large JSON-LD context files, increase heap size export NATIVE_IMAGE_OPTS="-J-Xmx6g" # Enable class initialization at build time -H:+InitializeAtBuildTime=fluree.json_ld ``` -------------------------------- ### Running Project Tests (Makefile) Source: https://github.com/fluree/json-ld/blob/main/README.md Lists the make commands for running various test suites within the Fluree JSON-LD project. This includes commands for running all tests, Clojure-specific tests, ClojureScript tests, JavaScript ESM tests (Node.js and browser), and conversion tests. ```bash $ make test # Run all tests (Clojure + JavaScript ESM) $ make cljtest # Run Clojure tests only $ make cljstest # Run ClojureScript tests only (auto-installs npm deps) $ make esm-test # Run JavaScript ESM tests only $ make esm-test-node # Run Node.js ESM tests only $ make esm-test-conversion # Run JS<->CLJ data conversion tests $ make test-ci # Run all tests for CI/CD $ make test-ci-workflow # Test complete CI workflow locally ``` -------------------------------- ### Compare JVM vs. Native Image Memory Usage (Bash) Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md This snippet shows how to compare the memory usage of a Java application on the JVM versus its native image counterpart. For the JVM, it uses `PrintGCDetails` to log garbage collection information, which can be analyzed for memory consumption. For the native image, memory usage should be monitored using system tools. This comparison helps identify memory optimization opportunities. ```bash # Memory usage comparison java -XX:+PrintGCDetails -jar target/your-app.jar # vs native image (check with system tools) ``` -------------------------------- ### Common Fluree JSON-LD Integration Patterns Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md Illustrates common Clojure patterns for using Fluree JSON-LD, including pre-parsing contexts at startup, creating reusable compaction functions, and normalizing data for consistent hashing. ```clojure ;; Pattern 1: Pre-parse contexts at startup (def ^:const default-context (jld/parse-context {"name" "http://schema.org/name" "Person" "http://schema.org/Person"})) ;; Pattern 2: Create reusable compaction functions (def compact-schema-org (jld/compact-fn default-context)) ;; Pattern 3: Normalize data for consistent hashing (defn content-hash [json-ld-data] (-> json-ld-data jld/normalize-data hash)) ``` -------------------------------- ### Building JavaScript Modules (Makefile) Source: https://github.com/fluree/json-ld/blob/main/README.md Shows the make commands used to build the JavaScript ESM modules for the Fluree JSON-LD library. These commands allow for building both Node.js and browser compatible modules, or individually. ```bash make js-package # Build both Node.js and browser ESM modules make node # Build Node.js ESM module only make browser # Build browser ESM module only ``` -------------------------------- ### Get Index Path of Expanded Item (Clojure) Source: https://context7.com/fluree/json-ld/llms.txt Returns the original index path of an expanded item within a JSON-LD document. This is useful for error reporting to pinpoint the item's origin in the source document. Requires the 'fluree.json-ld' namespace and uses the ':json-ld/idx' metadata added by the 'expand' function. ```clojure (require '[fluree.json-ld :as json-ld]) ;; The expand function adds :json-ld/idx metadata to values ;; Use get-idx to retrieve the path (def expanded (json-ld/expand {"@context" {"name" "http://schema.org/name"} "@id" "http://example.org/1" "name" "John"})) ;; Get index for a value (path in original document using get-in syntax) (json-ld/get-idx (get-in expanded ["http://schema.org/name" 0])) ;; => Returns path like ["name"] indicating where value came from ``` -------------------------------- ### Run fluree/json-ld Native Binary Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md Executes the compiled fluree/json-ld native binary. This command allows you to test the performance and functionality of the native image. ```bash # Test the generated native binary ./fluree-json-ld ``` -------------------------------- ### Run GraalVM Compatibility Tests Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md Executes compatibility tests for fluree/json-ld with GraalVM. This script verifies that the library functions correctly within the GraalVM environment. ```bash # Run compatibility tests ./graalvm/test/run-graal-test.sh ``` -------------------------------- ### Expand Compact IRI with Context Source: https://context7.com/fluree/json-ld/llms.txt Expands a compact IRI to its full form using a parsed JSON-LD context. The `vocab?` parameter determines whether to use the `@vocab` or `@base` directive from the context for expansion. Non-matching or already full IRIs are returned unchanged. ```clojure (require '[fluree.json-ld :as json-ld]) ;; Parse a context first (def ctx (json-ld/parse-context {"@context" {"schema" "http://schema.org/"}})) ;; Expand a compact IRI (vocab mode - default) (json-ld/expand-iri "schema:name" ctx) ;; => "http://schema.org/name" ;; Expand with vocab? = true (explicit) (json-ld/expand-iri "schema:Person" ctx true) ;; => "http://schema.org/Person" ;; Non-matching IRIs returned unchanged (json-ld/expand-iri "not:matching" ctx true) ;; => "not:matching" ;; Already full IRIs returned unchanged (json-ld/expand-iri "http://example.org/ns#Book" ctx true) ;; => "http://example.org/ns#Book" ;; Context with direct term mapping (def ctx2 (json-ld/parse-context {"@context" {"REPLACE" "http://schema.org/Person"}})) (json-ld/expand-iri "REPLACE" ctx2 true) ;; => "http://schema.org/Person" ``` -------------------------------- ### Recommended Usage Pattern for Fluree JSON-LD Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md Demonstrates recommended Clojure functions for processing JSON-LD data using Fluree. It highlights core functionality and pure Clojure implementations, advising against JavaScript-dependent modules for GraalVM compatibility. ```clojure (ns your-app (:require [fluree.json-ld :as jld] ; ✅ Core functionality [fluree.json-ld.impl.normalize :as norm]) ; ✅ Pure Clojure ;; Avoid: fluree.json-ld.processor.api ; ❌ Requires JavaScript ) ;; ✅ GraalVM-compatible functions (defn process-json-ld [data context-map] (let [parsed-context (jld/parse-context context-map) expanded (jld/expand data) normalized (jld/normalize-data data)] {:parsed-context parsed-context :expanded expanded :normalized normalized})) ;; ✅ IRI operations (defn expand-and-compact-iri [compact-iri context-map] (let [parsed-context (jld/parse-context context-map) expanded (jld/expand-iri compact-iri parsed-context) compact-fn (jld/compact-fn parsed-context)] {:expanded expanded :compacted (compact-fn expanded)})) ``` -------------------------------- ### Copy fluree/json-ld Reflection Configuration Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md Copies the reflection configuration file from the fluree/json-ld module to the project's GraalVM configuration directory. This ensures that the native image build has the necessary metadata for reflection. ```bash # Option 1: Copy the config cp node_modules/fluree-json-ld/graalvm/configs/reflect-config.json graalvm/ ``` -------------------------------- ### Trace Missing Classes with Java Agent (Bash) Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md This bash command utilizes the GraalVM tracing agent (`native-image-agent`) to identify missing classes during the execution of Clojure tests. The agent collects runtime information, including class loading, and outputs it to a specified directory (`test-trace`). This trace data is essential for configuring GraalVM Native Image to include all necessary classes for successful compilation. The command also sets up the classpath using `clojure -Spath`. ```bash # Use tracing agent during tests java -agentlib:native-image-agent=config-output-dir=test-trace \ -cp $(clojure -Spath) clojure.main -m graal-compat-test ``` -------------------------------- ### Code Quality and Formatting (Makefile) Source: https://github.com/fluree/json-ld/blob/main/README.md Details the make commands for maintaining code quality and formatting within the Fluree JSON-LD project. This includes linting with `clj-kondo` and auto-formatting code. ```bash $ make lint # Run clj-kondo linter $ make lint-ci # Run stricter CI linting $ make fmt # Auto-format code $ make fmt-check # Check formatting without changing files ``` -------------------------------- ### details Source: https://context7.com/fluree/json-ld/llms.txt Retrieves expanded IRI and context settings for a given term. Useful for debugging context configurations and understanding term resolution. ```APIDOC ## details ### Description Returns the expanded IRI along with its context settings. Useful for debugging context configurations and understanding how terms are resolved. ### Method `json-ld/details` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **term** (string) - The term (e.g., a prefixed name or IRI) to get details for. - **context** (map) - The parsed JSON-LD context. - **vocab?** (boolean, optional) - Controls whether to expand terms as vocabulary terms or @id. Defaults to false. ### Request Example ```clojure (require '[fluree.json-ld :as json-ld]) ;; Get expansion details for a term (def ctx (json-ld/parse-context {"@context" {"schema" "http://schema.org/"}})) (json-ld/details "schema:name" ctx) ;; => ["http://schema.org/name" {:id "http://schema.org/", ...}] ;; Details for @reverse properties (def ctx2 (json-ld/parse-context {"@context" {"schema" "http://schema.org/" "parent" {"@reverse" "schema:child"}}})) (json-ld/details "parent" ctx2 true) ;; => ["http://schema.org/child" {:reverse "http://schema.org/child"}] ``` ### Response #### Success Response (200) Returns a vector containing the expanded IRI and its associated context settings. #### Response Example ``` ["http://schema.org/name" {:id "http://schema.org/", ...}] ``` ``` -------------------------------- ### Run Fluree JSON-LD GraalVM Compatibility Test Suite Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md Command to execute the comprehensive GraalVM compatibility tests for Fluree JSON-LD. This script runs assertions across core API functions to ensure proper integration. ```bash # Run comprehensive GraaVM compatibility tests ./graalvm/test/run-graal-test.sh ``` -------------------------------- ### Build fluree/json-ld Native Image Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md Builds the fluree/json-ld project into a JAR file and then compiles it into a GraalVM native image. This script orchestrates the native image compilation process. ```bash # Build JAR and compile to native image ./graalvm/configs/native-image.sh ``` -------------------------------- ### Add Debug Flags for Native Image Build Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md Includes additional debug flags when building a native image using the `native-image` command. These flags provide detailed analysis and dashboard output to aid in debugging the build process. ```bash # Add debug flags to native-image.sh native-image \ -H:+PrintAnalysisCallTree \ -H:+DashboardAll \ -H:DashboardDump=build-dashboard \ # ... other flags ``` -------------------------------- ### Discover Missing Reflection Configuration with GraalVM Tracing Agent Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md Uses the GraalVM tracing agent to discover and output missing reflection configurations. This command helps in identifying and resolving reflection-related issues during native image builds. ```bash # Use GraalVM tracing agent to discover missing configuration java -agentlib:native-image-agent=config-output-dir=graalvm/configs \ -cp your-app.jar your.main.Class ``` -------------------------------- ### Compact Expanded IRI with Context Source: https://context7.com/fluree/json-ld/llms.txt Compacts an expanded IRI into its shortest possible representation using a provided parsed context or a compact function. If an IRI is not found within the context, it is returned unchanged. This function is useful for generating human-readable JSON-LD. ```clojure (require '[fluree.json-ld :as json-ld]) ;; Parse a context (def ctx (json-ld/parse-context {"@context" {"schema" "http://schema.org/"}})) ;; Compact an IRI directly (json-ld/compact "http://schema.org/name" ctx) ;; => "schema:name" ;; Compact using a compact function (def compact-fn (json-ld/compact-fn ctx)) (compact-fn "http://schema.org/Person") ;; => "schema:Person" ;; IRIs not in context returned unchanged (compact-fn "http://example.org/unknown") ;; => "http://example.org/unknown" ``` -------------------------------- ### Debug Reflection Issues with GraalVM Tracing Agent Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md Instructions for using the GraalVM tracing agent to identify missing reflection configurations. This involves running your application with the agent and comparing the discovered configuration with your existing `reflect-config.json`. ```bash # Use tracing agent to discover missing reflection config java -agentlib:native-image-agent=config-output-dir=graalvm/discovered \ -cp target/your-app.jar \ your.main.Class # Compare with existing config diff graalvm/reflect-config.json graalvm/discovered/reflect-config.json ``` -------------------------------- ### JSON-LD IRI Expansion API Source: https://context7.com/fluree/json-ld/llms.txt Expands a compact IRI to its full form using a parsed context. The `vocab?` parameter determines whether to use `@vocab` or `@base` for expansion. ```APIDOC ## POST /json-ld/expand-iri ### Description Expands a compact IRI to its full form using a parsed context. The `vocab?` parameter controls whether to use `@vocab` (for properties/classes) or `@base` (for `@id` values). ### Method POST ### Endpoint /json-ld/expand-iri ### Parameters #### Request Body - **iri** (string) - Required - The compact IRI to expand. - **context** (object) - Required - The parsed JSON-LD context. - **vocab** (boolean) - Optional - If true, uses `@vocab`; otherwise, uses `@base`. Defaults to true. ### Request Example ```json { "iri": "schema:name", "context": { "@context": {"schema": "http://schema.org/"} }, "vocab": true } ``` ### Response #### Success Response (200) - **expanded_iri** (string) - The expanded IRI. #### Response Example ```json { "expanded_iri": "http://schema.org/name" } ``` ``` -------------------------------- ### Loading Pre-fetched External Contexts (Clojure) Source: https://github.com/fluree/json-ld/blob/main/README.md Demonstrates how to load pre-parsed contexts for common vocabularies directly within Clojure using the `json-ld/external-context` function. This simplifies the process of working with standard schemas like Schema.org or W3C DID. ```clojure ;; Load a pre-fetched external context (json-ld/external-context "https://schema.org") ;; Load vocabulary information for an IRI (json-ld/external-vocab "http://schema.org/Person") ``` -------------------------------- ### JSON-LD Compaction API Source: https://context7.com/fluree/json-ld/llms.txt Compacts an expanded IRI using a parsed context or a compact function, returning the shortest possible representation. ```APIDOC ## POST /json-ld/compact ### Description Compacts an expanded IRI using a parsed context or compact function. Returns the shortest representation possible based on the context. ### Method POST ### Endpoint /json-ld/compact ### Parameters #### Request Body - **iri** (string) - Required - The IRI to compact. - **context** (object) - Required - The parsed JSON-LD context or a compact function definition. ### Request Example ```json { "iri": "http://schema.org/name", "context": { "@context": {"schema": "http://schema.org/"} } } ``` ### Response #### Success Response (200) - **compacted_iri** (string) - The compacted IRI. #### Response Example ```json { "compacted_iri": "schema:name" } ``` ``` -------------------------------- ### external-context Source: https://context7.com/fluree/json-ld/llms.txt Fetches and parses a pre-loaded context for common vocabularies by URL. Returns nil if the context is not available. ```APIDOC ## external-context ### Description Returns a pre-loaded parsed context for common vocabularies by URL. Returns nil if the context is not available. ### Method `json-ld/external-context` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **url** (string) - The URL of the external context to load. ### Request Example ```clojure (require '[fluree.json-ld :as json-ld]) ;; Load Schema.org context (def schema-ctx (json-ld/external-context "https://schema.org")) ;; => Returns parsed context with Schema.org terms (contains? schema-ctx "Person") ;; => true ;; Load Fluree ledger context (def fluree-ctx (json-ld/external-context "https://ns.flur.ee/ledger/v1")) ;; => Returns parsed Fluree ledger context ;; Non-existent contexts return nil (json-ld/external-context "https://example.com/nonexistent") ;; => nil ;; Available pre-loaded contexts: ;; - https://schema.org ;; - https://www.w3.org/2018/credentials/v1 ;; - https://www.w3.org/ns/did/v1 ;; - http://www.w3.org/ns/shacl ;; - https://ns.flur.ee/ledger/v1 ``` ### Response #### Success Response (200) Returns a parsed context map if the URL is recognized and the context is available, otherwise returns `nil`. #### Response Example ```clojure {"@context" {"schema" "http://schema.org/"}, ...} ``` ``` -------------------------------- ### Integrate Fluree JSON-LD in Upstream GraalVM Projects Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md A Clojure test case demonstrating how to integrate and test Fluree JSON-LD within an upstream GraalVM project's test suite. It verifies context parsing, IRI expansion, and data normalization. ```clojure ;; Add to your test suite (deftest our-graal-integration (testing "fluree/json-ld integration in our GraalVM build" (let [our-context {"title" "http://purl.org/dc/terms/title" "author" "http://purl.org/dc/terms/creator"} parsed (jld/parse-context our-context) doc {"@context" our-context "title" "My Document" "author" "Jane Doe"} normalized (jld/normalize-data doc)] ;; Verify parsing works (is (map? parsed)) (is (contains? parsed "title")) ;; Verify IRI expansion (is (= "http://purl.org/dc/terms/title" (jld/expand-iri "title" parsed))) ;; Verify normalization (is (string? normalized)) (is (.contains normalized "Jane Doe"))))) ``` -------------------------------- ### JSON-LD Operations in ClojureScript Source: https://github.com/fluree/json-ld/blob/main/README.md Illustrates the usage of the Fluree JSON-LD library within a ClojureScript environment. It shows how to require the library and utilize core functions like `parse-context`, `expand`, and `compact` with ClojureScript data structures. ```clojure (ns my-app.core (:require [fluree.json-ld :as json-ld])) ;; All the same functions work in ClojureScript (def ctx (json-ld/parse-context {"@context" {...}})) (def expanded (json-ld/expand my-json-ld-doc ctx)) (def compacted-iri (json-ld/compact "http://schema.org/name" ctx)) ``` -------------------------------- ### Test Fluree JSON-LD Integration in GraalVM Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md A Clojure test case to verify that Fluree JSON-LD functions correctly within a GraalVM build. It checks context parsing, data normalization, and IRI expansion. ```clojure (ns your-app.graal-test (:require [fluree.json-ld :as jld] [clojure.test :refer [deftest is testing]])) (deftest graal-integration-test (testing "fluree/json-ld works in your GraalVM build" (let [doc {"@context" {"name" "http://schema.org/name"} "name" "Test"} parsed-context (jld/parse-context {"name" "http://schema.org/name"}) normalized (jld/normalize-data doc)] (is (map? parsed-context)) (is (string? normalized)) (is (= "http://schema.org/name" (jld/expand-iri "name" parsed-context)))))) ``` -------------------------------- ### Compact IRIs using a parsed context - Clojure Source: https://context7.com/fluree/json-ld/llms.txt Creates a function that compacts expanded IRIs into prefixed terms based on a provided JSON-LD context. Optionally, it can track which context terms were utilized during compaction, which is useful for identifying the subset of a context that was actually needed. ```clojure (require '[fluree.json-ld :as json-ld]) ;; Basic compact function (def ctx (json-ld/parse-context {"@context" {"schema" "http://schema.org/"}})) (def compact-fn (json-ld/compact-fn ctx)) (compact-fn "http://schema.org/name") ;; => "schema:name" (compact-fn "http://schema.org/Person") ;; => "schema:Person" ;; Track which context terms were used (def used (atom {})) (def tracked-compact-fn (json-ld/compact-fn ctx used)) (tracked-compact-fn "http://schema.org/name") ;; => "schema:name" (tracked-compact-fn "http://schema.org/email") ;; => "schema:email" @used ;; => {"schema" {:id "http://schema.org/", ...}} ;; Useful for identifying which subset of a large context (like Schema.org) was actually needed ``` -------------------------------- ### Expand JSON-LD with Clojure Keywords Source: https://context7.com/fluree/json-ld/llms.txt Demonstrates expanding JSON-LD data using Clojure keywords for context terms and IRI values. This leverages the fluree.json-ld library to process semantic data in a Clojure-friendly manner. It requires the fluree.json-ld library to be required. ```clojure (require '[fluree.json-ld :as json-ld]) ;; Keyword contexts (json-ld/expand {:context {:id "@id" :type "@type" :schema "http://schema.org/"} :id "http://example.com/ns#item123" :type :schema/Movie :schema/name "My Movie"}) ;; => {"@type" ["http://schema.org/Movie"] ;; "@id" "http://example.com/ns#item123" ;; "http://schema.org/name" [{"@value" "My Movie"}]} ;; Keywords as IRI values (json-ld/expand {:context {:id "@id" :ex "http://example.com/ns#"} :id :ex/item123 :ex/favColor [:ex/red :ex/green]}) ;; => {"@id" "http://example.com/ns#item123" ;; "http://example.com/ns#favColor" [{"@id" "http://example.com/ns#red"} ;; {"@id" "http://example.com/ns#green"}]} ``` -------------------------------- ### Increase JVM Memory for Testing (Bash) Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md This snippet shows how to increase the maximum heap size for the Java Virtual Machine (JVM) when running tests, which can be particularly useful when dealing with memory-intensive applications or when debugging memory-related issues with GraalVM. The `JAVA_OPTS` environment variable is set to `-Xmx4g` to allocate 4 gigabytes of memory, and then the test script `run-graal-test.sh` is executed. This ensures sufficient memory is available for the tests to complete without running out of space. ```bash # Increase memory for testing export JAVA_OPTS="-Xmx4g" ./graalvm/test/run-graal-test.sh ``` -------------------------------- ### Handle JSON-LD Language Tags (Clojure) Source: https://context7.com/fluree/json-ld/llms.txt Supports JSON-LD language tags for internationalized string values. Demonstrates usage with explicit language tags, default language in context, and language maps with '@container'. Requires the 'fluree.json-ld' namespace. ```clojure (require '[fluree.json-ld :as json-ld]) ;; Language tags in value maps (json-ld/expand {"@context" {"ex" "http://example.com/vocab/"} "ex:name" "Frank" "ex:occupation" {"@value" "Ninja" "@language" "en"}}) ;; => {"http://example.com/vocab/name" ["@value" "Frank"] ;; "http://example.com/vocab/occupation" ["@value" "Ninja" "@language" "en"]} ;; Default language in context (json-ld/expand {"@context" {"ex" "http://example.com/vocab/" "@language" "en"} "ex:name" "Frank" "ex:age" 33}) ;; => {"http://example.com/vocab/name" ["@value" "Frank" "@language" "en"] ;; "http://example.com/vocab/age" [33]} ;; Note: Language tags only apply to string values ;; Language maps with @container (json-ld/expand {"@context" {"ex" "http://example.com/vocab/" "occupation" {"@id" "ex:occupation" "@container" "@language"}} "occupation" {"en" "Ninja" "ja" "忍者"}}) ;; => {"http://example.com/vocab/occupation" ["@value" "Ninja" "@language" "en" ;; "@value" "忍者" "@language" "ja"]} ``` -------------------------------- ### Retrieve vocabulary information for an IRI - Clojure Source: https://context7.com/fluree/json-ld/llms.txt Fetches detailed vocabulary information for a given IRI, including relationships like `rdfs:subClassOf`. If the vocabulary information for the specified IRI is not found or available, the function returns `nil`. ```clojure (require '[fluree.json-ld :as json-ld]) ;; Get vocabulary info for Schema.org term (json-ld/external-vocab "http://schema.org/Person") ;; => Returns vocabulary details if available, nil otherwise ;; Non-existent vocabulary returns nil (json-ld/external-vocab "http://example.com/nonexistent") ;; => nil ``` -------------------------------- ### Increase Memory Allocation for Native Image Build Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md Sets the NATIVE_IMAGE_OPTS environment variable to increase the memory allocated for the GraalVM native image build process. This is useful when encountering memory errors during compilation. ```bash # Increase memory allocation export NATIVE_IMAGE_OPTS="-J-Xmx8g" ``` -------------------------------- ### Load pre-parsed external JSON-LD contexts - Clojure Source: https://context7.com/fluree/json-ld/llms.txt Fetches and returns a pre-loaded parsed JSON-LD context for common vocabularies identified by their URLs. If the specified context is not available or has not been pre-loaded, the function returns `nil`. ```clojure (require '[fluree.json-ld :as json-ld]) ;; Load Schema.org context (def schema-ctx (json-ld/external-context "https://schema.org")) ;; => Returns parsed context with Schema.org terms (contains? schema-ctx "Person") ;; => true (contains? schema-ctx "name") ;; => true ;; Load Fluree ledger context (def fluree-ctx (json-ld/external-context "https://ns.flur.ee/ledger/v1")) ;; => Returns parsed Fluree ledger context (get-in fluree-ctx ["f" :id]) ;; => "https://ns.flur.ee/ledger#" ;; Non-existent contexts return nil (json-ld/external-context "https://example.com/nonexistent") ;; => nil ;; Available pre-loaded contexts: ;; - https://schema.org ;; - https://www.w3.org/2018/credentials/v1 ;; - https://www.w3.org/ns/did/v1 ;; - http://www.w3.org/ns/shacl ;; - https://ns.flur.ee/ledger/v1 ``` -------------------------------- ### Compact JSON-LD Documents (Clojure) Source: https://github.com/fluree/json-ld/blob/main/README.md Compact expanded JSON-LD data back into a shorter form using a provided context. This function can optionally track which terms from the context were utilized during the compaction process. ```clojure (require '[fluree.json-ld :as json-ld]) ;; Create a compacting function ;; (def compact-fn (json-ld/compact-fn parsed-context)) ;; (compact-fn "http://schema.org/name") ;; => "schema:name" ;; Track which context terms were used ;; (def used (atom #{})) ;; (def compact-fn (json-ld/compact-fn parsed-context used)) ;; (compact-fn "http://schema.org/name") ;; @used ;; => #{"schema"} ``` -------------------------------- ### Load External IRIs and Vocabulary Information (Clojure) Source: https://github.com/fluree/json-ld/blob/main/README.md Demonstrates how to load external IRIs and retrieve vocabulary information using the `json-ld/external-iri` and `json-ld/external-vocab` functions in Clojure. These functions are useful for inspecting and understanding external schema definitions. ```clojure ;; Load external IRIs with additional vocabulary information (json-ld/external-iri "http://schema.org/Person") ;; => Returns IRI information (json-ld/external-vocab "http://schema.org/name") ;; => Returns vocabulary details including rdfs:subClassOf relationships ``` -------------------------------- ### Enable Reflection Warnings in Clojure (Clojure) Source: https://github.com/fluree/json-ld/blob/main/graalvm/README.md This Clojure code snippet enables reflection warnings, which are crucial for identifying potential performance bottlenecks and compatibility issues when compiling with GraalVM Native Image. By setting `*warn-on-reflection*` to `true`, the compiler will output warnings for any reflection operations that occur during test execution. Re-running tests after enabling this setting will reveal specific warnings. ```clojure ;; Enable reflection warnings (set! *warn-on-reflection* true) ;; Re-run tests to see specific warnings ```