### Install Cool RDF CLI on Mac/Linux Source: https://rdf.cool/cool-rdf/cool-cli.html Convenience script to download the cool RDF CLI JAR and install it as a shell command. Ensure Java 25+ is installed. ```shell curl -L -o ~/.local/share/cool-rdf/cool-rdf-cli.jar --create-dirs https://github.com/cool-rdf/cool-rdf/releases/download/v2.0.0/cool-rdf-cli-2.0.0.jar echo 'function cool() { java -jar ~/.local/share/cool-rdf/cool-rdf-cli.jar $*; }' >> ~/.bashrc source ~/.bashrc ``` -------------------------------- ### Cool RDF CLI - Installation Source: https://rdf.cool/cool-rdf/cool-cli.html Instructions for installing the Cool RDF command line tool, including prerequisites and download links. ```APIDOC ## Cool RDF CLI - Installation ### Requirements * Java 25 or later. * Optional: Graphviz for diagram generation. * Windows: `choco install graphviz` * macOS: `brew install graphviz` * Ubuntu/Debian: `apt install graphviz` ### Download and Install `cool` Latest version: **2.0.0** Download: **cool-rdf-cli-2.0.0.jar** **macOS/Linux Convenience Script:** ```bash curl -L -o ~/.local/share/cool-rdf/cool-rdf-cli.jar --create-dirs https://github.com/cool-rdf/cool-rdf/releases/download/v2.0.0/cool-rdf-cli-2.0.0.jar echo 'function cool() { java -jar ~/.local/share/cool-rdf/cool-rdf-cli.jar $*; }' >> ~/.bashrc source ~/.bashrc ``` After installation, the `cool` command can be used. ``` -------------------------------- ### RDF/Turtle Serialization Examples Source: https://rdf.cool/cool-rdf/java-api.html Examples showing how the same RDF model can be serialized in different valid orders. ```turtle @prefix : . :test :blorb "blorb" ; :floop "floop" . ``` ```turtle @prefix : . :test :floop "floop" ; :blorb "blorb" . ``` -------------------------------- ### Execute RDF write command Source: https://rdf.cool/cool-rdf/cool-cli.html Examples of using the 'cool write' command to convert and format RDF files. ```bash # Read myontology.ttl and print it in formatted Turtle format cool write myontology.ttl # Read myontology.owl in RDF/XML format and print it in formatted Turtle format, writing output.ttl cool write -i rdfxml myontology.owl output.ttl # Read myontology.n3 in N3 format and print it in formatted Turtle format to stdout cool write -i n3 myontology.n3 ``` -------------------------------- ### Align Prefixes Example Source: https://rdf.cool/cool-rdf/java-api.html Illustrates the effect of the `alignPrefixes` option on RDF prefix formatting. When `true`, prefixes are aligned; when `false`, they are not. ```turtle # true @prefix rdf: . @prefix example: . # false @prefix rdf: . @prefix example: . ``` -------------------------------- ### First Predicate in New Line and Align Predicates Example Source: https://rdf.cool/cool-rdf/java-api.html Demonstrates the combined effect of `firstPredicateInNewLine` and `alignPredicates` on RDF statement formatting. Shows different layouts based on these boolean settings. ```turtle # firstPredicateInNewLine false # alignPredicates true :test a rdf:Resource ; :blorb "blorb" ; :floop "floop" . # firstPredicateInNewLine false # alignPredicates false :test a rdf:Resource ; :blorb "blorb" ; :floop "floop" . # firstPredicateInNewLine true # alignPredicates does not matter :test a rdf:Resource ; :blorb "blorb" ; :floop "floop" . ``` -------------------------------- ### Formatted RDF/Turtle Output Source: https://rdf.cool/cool-rdf/java-api.html An example of an RDF document formatted using the default style provided by cool-rdf-formatter. ```turtle @prefix rdfs: . __**(1)** @prefix owl: . @prefix : . :Male a owl:Class ; __**(2)** owl:disjointWith :Female ; __**(3)** owl:equivalentClass [ __**(4)** a owl:Restriction ; owl:hasSelf true ; __**(5)** owl:onProperty :isMale ; ] ; rdfs:subClassOf :Person . :hasBrother a owl:ObjectProperty ; owl:propertyChainAxiom ( :hasSibling :isMale ) ; __**(6)** rdfs:range :Male . :hasUncle a owl:ObjectProperty, owl:IrreflexiveProperty ; __**(7)** owl:propertyChainAxiom ( :hasParent :hasSibling :hasHusband ) ; __**(7)** owl:propertyChainAxiom ( :hasParent :hasBrother ) ; rdfs:range :Male . ``` -------------------------------- ### Align Objects Example Source: https://rdf.cool/cool-rdf/java-api.html Shows the impact of the `alignObjects` option on RDF formatting. When `true`, objects are aligned; when `false`, they are not. ```turtle # alignObjects true :test a rdf:Resource ; :blorb "blorb" ; :floopfloop "floopfloop" . # alignObjects false :test a rdf:Resource ; :blorb "blorb" ; :floopfloop "floopfloop" . ``` -------------------------------- ### Comma for Predicate Example Source: https://rdf.cool/cool-rdf/java-api.html Demonstrates the `commaForPredicate` option, which allows specifying predicates that should always use commas for separation, even when `useCommaByDefault` is `false`. This example shows `rdf:type` being comma-separated. ```turtle # useCommaByDefault false, commaForPredicate contains # 'rdf:type', firstPredicateInNewLine true :test a ex:something, owl:NamedIndividual ; :blorb "someBlorb" ; :blorb "anotherBlorb" . # useCommaByDefault false, commaForPredicate is empty, # firstPredicateInNewLine false :test a ex:something ; a owl:NamedIndividual ; :blorb "someBlorb" ; :blorb "anotherBlorb" . ``` -------------------------------- ### Use Comma by Default Example Source: https://rdf.cool/cool-rdf/java-api.html Illustrates the `useCommaByDefault` option. When `true`, multiple statements with the same predicate are comma-separated. When `false`, each statement is on a new line. ```turtle # useCommaByDefault false :test a rdf:Resource ; :blorb "someBlorb" ; :blorb "anotherBlorb" . # useCommaByDefault true :test a rdf:Resource ; :blorb "someBlorb", "anotherBlorb" . ``` -------------------------------- ### Anonymous Node ID Generation Source: https://rdf.cool/cool-rdf/java-api.html Example model demonstrating the need for anonymous node ID generation when blank nodes cannot be serialized using inline syntax. ```turtle :test :foo _:b0 . :test2 :bar _:b0 . ``` -------------------------------- ### Cool RDF CLI - General Usage Source: https://rdf.cool/cool-rdf/cool-cli.html Overview of how to use the Cool RDF command line tool and its general options. ```APIDOC ## Cool RDF CLI - General Usage ### Basic Invocation Call `cool` (or `java -jar cool-rdf-cli-2.0.0.jar`) with subcommands and arguments. ### Help To view general help and available commands: ```bash cool --help ``` ```text Usage: Usage: owl [-Dhv] [--version] [COMMAND] Description: Command line tool for ontology engineering Options: --help Show short help -v, --verbose Specify multiple -v options to increase verbosity, e.g. use `-v`, `-vv` or `-vvv` for more details --version Show current version Commands: ... ``` ### Subcommands Commands take their own arguments. For example: ```bash cool diagram --format png ``` Supported ontology input formats include RDF/Turtle, RDF/XML, OWL/XML, and OWL Functional Syntax. ``` -------------------------------- ### Generate Diagram to Standard Out and Convert Format Source: https://rdf.cool/cool-rdf/cool-cli.html Generates a diagram from an ontology file and pipes the output to standard out, which is then piped to 'convert' to create a JPG image. ```shell cool diagram myontology.ttl - | convert - myontology.jpg ``` -------------------------------- ### Cool RDF CLI General Help Source: https://rdf.cool/cool-rdf/cool-cli.html Displays the general help message for the Cool RDF command line tool, outlining usage, options, and available commands. ```shell Usage: Usage: owl [-Dhv] [--version] [COMMAND] Description: Command line tool for ontology engineering Options: --help Show short help -v, --verbose Specify multiple -v options to increase verbosity, e.g. use `-v`, `-vv` or `-vvv` for more details --version Show current version Commands: ... ``` -------------------------------- ### Write RDF with Prefixes Source: https://rdf.cool/cool-rdf/cool-cli.html Reads an N-Triples file and writes formatted Turtle, configuring specific prefixes for use. Use '-p' followed by the prefix and namespace, or '-p' with a predefined prefix like 'xsd'. ```shell cool write -prdf -powl -pxsd -p'ex=http://example.com#' -i ntriple myontology.nt ``` -------------------------------- ### Create Custom Formatting Style Source: https://rdf.cool/cool-rdf/java-api.html Shows how to create a custom `FormattingStyle` object using a builder pattern. This allows for fine-grained control over various formatting aspects. ```java FormattingStyle style = FormattingStyle.builder(). ... .build(); ``` -------------------------------- ### Formatting RDF Models Source: https://rdf.cool/cool-rdf/java-api.html Demonstrates how to initialize a TurtleFormatter with a specific style and apply it to a Jena Model to generate formatted Turtle output. ```APIDOC ## Java RDF Formatting ### Description Use the TurtleFormatter to transform a Jena Model into a formatted Turtle string or write it directly to an output stream. ### Method Java Class Usage ### Request Example ```java FormattingStyle style = FormattingStyle.DEFAULT; TurtleFormatter formatter = new TurtleFormatter(style); Model model = ModelFactory.createDefaultModel(); model.read(new FileInputStream("data.ttl"), style.emptyRdfBase, "TURTLE"); String prettyPrintedModel = formatter.apply(model); formatter.accept(model, System.out); ``` ``` -------------------------------- ### Download, Filter, and Generate Diagram Source: https://rdf.cool/cool-rdf/cool-cli.html Downloads an ontology from a URL, filters out specific comment lines using grep, and then pipes the result to 'cool diagram' to generate a 'partof.svg' file. ```shell curl http://www.ontologydesignpatterns.org/cp/owl/partof.owl | \ grep -v 'comment|cpannotation|versionInfo' | cool diagram - partof.svg ``` -------------------------------- ### CLI Command: cool write Source: https://rdf.cool/cool-rdf/cool-cli.html The write command processes RDF input files or URLs and outputs them in a specified format with optional formatting configurations. ```APIDOC ## CLI Command: cool write ### Description Reads an RDF file, URL, or standard input and writes it to a file or standard output in a specified format. Supports extensive formatting options for Turtle output. ### Method CLI Command ### Endpoint cool write [options] input [output] ### Parameters #### Path Parameters - **input** (string) - Required - The source RDF file, URL (http/https), or '-' for standard input. - **output** (string) - Optional - The destination file path or '-' for standard output. #### Options - **-o, --output** (string) - Optional - Output file format. Values: [turtle, rdfxml, ntriple, n3]. Default: turtle. - **-i, --input** (string) - Optional - Input file format. Values: [turtle, rdfxml, ntriple, n3]. Default: turtle. - **-p, --prefix** (string) - Optional - Prefix with URI to add as @prefix. Can be specified multiple times. - **--prefixAlign** (string) - Optional - Alignment of @prefix statements. Values: [left, off, right]. Default: off. - **--encoding** (string) - Optional - Output encoding. Values: [latin1, utf_16_be, utf_16_le, utf_8, utf_8_bom]. Default: utf_8. - **--indentSize** (integer) - Optional - Indentation size in spaces. Default: 2. ### Request Example # Read myontology.owl in RDF/XML format and print it in formatted Turtle format, writing output.ttl cool write -i rdfxml myontology.owl output.ttl ``` -------------------------------- ### Write Turtle with Formatting Source: https://rdf.cool/cool-rdf/cool-cli.html Reads a Turtle file and prints it with configured output formatting and prefix order. Use '--indentSize' for indentation and '--writeRdfType' to include RDF types. Specify prefix order with '--prefixOrder'. ```shell cool write --indentSize 4 --writeRdfType --prefixOrder owl --prefixOrder rdf myontology.turtle ``` -------------------------------- ### Cool RDF CLI - `diagram` Command Source: https://rdf.cool/cool-rdf/cool-cli.html Detailed documentation for the `diagram` command, used to generate visual diagrams from OWL ontologies. ```APIDOC ## `diagram` Command The `diagram` command generates diagrams from OWL ontologies in SVG or PNG format using Graphviz. ### General Usage `cool diagram [options] input [output]` * `input`: Ontology file path or `-` (standard input). * `output`: Output file path or `-` (standard output). If not provided, the output filename is derived from the input filename (e.g., `myontology.ttl` becomes `myontology.svg`). If input is `-`, output defaults to standard output. ### Options | Option | Description | Default | Notes | |----------------|---------------------------------------------------|---------------|---------------------------------------------| | `--direction` | Diagram layout direction | `left_to_right` | `top_to_bottom`, `left_to_right` | | `--dotbinary` | Path to `dot` binary | `dot` | Searches in `$PATH` by default | | `--fontname` | Default font | `Verdana` | | | `--fontsize` | Default font size | `12` | | | `--format` | Output file format | `svg` | `png`, `svg` | | `--nodefontname`| Font for nodes | `Verdana` | | | `--nodefontsize`| Font size for nodes | `Verdana` | | | `--nodemargin` | Margin inside nodes | `0.05,0.0` | See Graphviz documentation | | `--nodeshape` | Node shape | `box` | See Graphviz documentation | | `--nodestyle` | Node style | `rounded` | See Graphviz documentation | | `--fgcolor` | Color for boxes, fonts, and edges | `white` | See Graphviz documentation | | `--bgcolor` | Background color for the generated diagram | `white` | See Graphviz documentation | ### Example Usage **Simple invocation:** ```bash # Creates myontology.svg cool diagram myontology.ttl ``` **Output to standard out and pipe to convert:** ```bash cool diagram myontology.ttl - | convert - myontology.jpg ``` **Download, filter, and generate diagram:** ```bash curl http://www.ontologydesignpatterns.org/cp/owl/partof.owl | \ grep -v 'comment|cpannotation|versionInfo' | cool diagram - partof.svg ``` ``` -------------------------------- ### Infer OWL Reasoning Results Source: https://rdf.cool/cool-rdf/cool-cli.html Performs OWL 2 DL reasoning on an input ontology and writes the results to standard output. The input can be a file, URL, or standard input ('-'). ```shell cool infer ontology.ttl - ``` -------------------------------- ### Customizing FormattingStyle Source: https://rdf.cool/cool-rdf/java-api.html Explains how to use the FormattingStyle builder to configure output preferences like indentation, prefix alignment, and quote styles. ```APIDOC ## Customizing FormattingStyle ### Description Configure the output format by creating a custom FormattingStyle object using the builder pattern. ### Parameters - **emptyRdfBase** (String) - URI to be left out in formatting. Default: urn:cool-rdf:empty - **alignPrefixes** (Boolean) - Whether to align prefix definitions. Default: false - **alignPredicates** (Boolean) - Whether to align predicates. Default: false - **firstPredicateInNewLine** (Boolean) - Whether the first predicate starts on a new line. Default: false - **alignObjects** (Boolean) - Whether to align objects. Default: false - **charset** (Enum) - Character set (LATIN1, UTF_16_BE, UTF_16_LE, UTF_8, UTF_8_BOM). Default: UTF_8 - **indentStyle** (Enum) - SPACE or TAB. Default: SPACE - **indentSize** (Integer) - Indentation size for SPACE style. Default: 2 - **useAForRdfType** (Boolean) - Whether to use 'a' for rdf:type. Default: true - **useCommaByDefault** (Boolean) - Whether to use commas for identical predicates. Default: false ### Request Example ```java FormattingStyle style = FormattingStyle.builder() .indentSize(4) .useAForRdfType(true) .build(); ``` ``` -------------------------------- ### Write RDF to Stdout Source: https://rdf.cool/cool-rdf/cool-cli.html Reads an ontology in N-Triples format and prints it to standard output in RDF/XML format. ```shell cool write -i ntriple -o rdfxml myontology.nt ``` -------------------------------- ### Cool RDF Diagram Command Basic Usage Source: https://rdf.cool/cool-rdf/cool-cli.html Basic invocation of the 'diagram' command with an input ontology file. The output format defaults to SVG and the output filename is derived from the input filename. ```shell cool diagram --format png ``` -------------------------------- ### Call RDF Formatter with Default Style Source: https://rdf.cool/cool-rdf/java-api.html Demonstrates how to initialize and use the TurtleFormatter with the default formatting style to format an RDF model read from a file. It shows both converting the model to a string and writing it directly to an output stream. ```java import java.io.FileInputStream; import cool.rdf.formatter.FormattingStyle; import cool.rdf.formatter.TurtleFormatter; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; // ... // Determine formatting style FormattingStyle style = FormattingStyle.DEFAULT; TurtleFormatter formatter = new TurtleFormatter(style); // Build or load a Jena Model. // Use the style's base URI for loading the model. Model model = ModelFactory.createDefaultModel(); model.read(new FileInputStream("data.ttl"), style.emptyRdfBase, "TURTLE"); // Either create a string... String prettyPrintedModel = formatter.apply(model); // ...or write directly to an OutputStream formatter.accept(model, System.out); ``` -------------------------------- ### Gradle Dependency Configuration Source: https://rdf.cool/cool-rdf/java-api.html Include these lines in your build.gradle files to add the library dependency. ```groovy implementation 'de.atextor:turtle-formatter:2.0.0' ``` ```kotlin implementation("de.atextor:turtle-formatter:2.0.0") ``` -------------------------------- ### Standard Apache Jena Model Write Source: https://rdf.cool/cool-rdf/java-api.html The default way to write an RDF model using Apache Jena, which may result in non-deterministic output order. ```java model.write(System.out, "TURTLE") ``` -------------------------------- ### Define Namespace Prefix Order Source: https://rdf.cool/cool-rdf/java-api.html Sets the priority order for namespace prefixes in the output. ```turtle @prefix rdf: . @prefix owl: . @prefix example: . ``` -------------------------------- ### Generate Ontology Diagram Source: https://rdf.cool/cool-rdf/cool-cli.html Generates an SVG diagram from an ontology file using default settings. The output file will be named 'myontology.svg'. ```shell cool diagram myontology.ttl ``` -------------------------------- ### Read Remote Ontology Source: https://rdf.cool/cool-rdf/cool-cli.html Reads a remote ontology in RDF/XML format and prints it in formatted Turtle format. URLs should be enclosed in single quotes. ```shell cool write -i rdfxml 'http://www.ontologydesignpatterns.org/cp/owl/partof.owl' ``` -------------------------------- ### Configure Predicate Ordering Source: https://rdf.cool/cool-rdf/java-api.html Defines the order in which predicates appear for a subject, with specified properties appearing first followed by lexicographical sorting. ```turtle :test :z "z" ; :x "x" ; :a "a" . ``` -------------------------------- ### Maven Dependency Configuration Source: https://rdf.cool/cool-rdf/java-api.html Add this dependency to your pom.xml to include the cool-rdf-formatter library in your project. ```xml cool.rdf cool-rdf-formatter 2.0.0 ``` -------------------------------- ### RDF Serialization Configuration Source: https://rdf.cool/cool-rdf/java-api.html Configuration options for controlling the serialization of RDF data, including ordering and formatting. ```APIDOC ## RDF Serialization Configuration This section details the configuration options available for customizing the RDF serialization process, focusing on ordering of elements and formatting. ### `prefixOrder` **Description**: Specifies the order of prefixes to appear at the top of the serialized output. Prefixes listed here will appear first, followed by all other namespaces in lexicographical order. **Type**: `List` **Example**: `List.of("rdf", "owl")` ### `subjectOrder` **Description**: A list of resources that determines the order in which subjects appear in the output. For a subject `s` to be ordered, there must be a statement `s rdf:type t` where `t` is present in the `subjectOrder` list. Subjects not in the list are sorted lexicographically. **Type**: `List` **Example**: `List.of(rdfs:Class, owl:Ontology, owl:Class, rdf:Property, owl:ObjectProperty, owl:DatatypeProperty, owl:AnnotationProperty, owl:NamedIndividual, owl:AllDifferent, owl:Axiom)` ### `predicateOrder` **Description**: A list of properties that dictate the order of predicates for a given subject. Properties in the list appear in the specified order, followed by all other properties sorted lexicographically. **Type**: `List` **Example**: `List.of(rdf:type, rdfs:label, rdfs:comment, dcterms:description)` ### `objectOrder` **Description**: A list of RDFNodes (resources or literals) that control the order of objects for a specific subject-predicate pair. Objects in the list appear first in the specified order, followed by others sorted lexicographically. **Type**: `List` **Example**: `List.of(owl:NamedIndividual, owl:ObjectProperty, owl:DatatypeProperty, owl:AnnotationProperty, owl:FunctionalProperty, owl:InverseFunctionalProperty, owl:TransitiveProperty, owl:SymmetricProperty, owl:AsymmetricProperty, owl:ReflexiveProperty, owl:IrreflexiveProperty)` ### `anonymousNodeIdGenerator` **Description**: A `BiFunction` used to generate names for blank nodes (anonymous nodes) in the formatted output when they need to be locally named. It takes a resource (blank node) and a counter, returning a string for the blank node's identifier. **Type**: `BiFunction` **Example**: `(r, i) -> "gen" + i` ### Formatting Options **Description**: Various options to control whitespace and line breaks in the serialized output. These include settings for gaps, line breaks, and list item wrapping. **Options**: `{after,before}{Opening,Closing}{Parenthesis,SquareBrackets}`, `{after,before}{Comma,Dot,Semicolon}`, `wrapListItems` **Values**: `NEWLINE`, `NOTHING`, `SPACE`, `ALWAYS`, `NEVER`, `FOR_LONG_LINES` **Note**: It is generally recommended to use the default formatting options as they align with common best practices for Turtle serialization. ``` -------------------------------- ### Configure Object Ordering Source: https://rdf.cool/cool-rdf/java-api.html Determines the order of objects for a predicate when multiple statements share the same subject and predicate. ```turtle :test a :Foo, :Bar . ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.