diff --git a/Gemfile b/Gemfile index 54b6072f..237ba38d 100644 --- a/Gemfile +++ b/Gemfile @@ -22,6 +22,7 @@ group :jekyll_plugins do gem 'jekyll-sitemap' gem 'jekyll-feed' gem 'jekyll-seo-tag' + gem 'jekyll-tabs' end # Windows does not include zoneinfo files, so bundle the tzinfo-data gem diff --git a/Gemfile.lock b/Gemfile.lock index ec16d468..fda3e9ec 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -158,6 +158,8 @@ GEM jekyll-sitemap (1.4.0) jekyll (>= 3.7, < 5.0) jekyll-swiss (1.0.0) + jekyll-tabs (1.2.1) + jekyll (>= 3.0, < 5.0) jekyll-theme-architect (0.2.0) jekyll (> 3.5, < 5.0) jekyll-seo-tag (~> 2.0) @@ -271,6 +273,7 @@ DEPENDENCIES jekyll-feed jekyll-seo-tag jekyll-sitemap + jekyll-tabs tzinfo-data webrick (~> 1.7) diff --git a/_config.yml b/_config.yml index a43d8944..85351614 100644 --- a/_config.yml +++ b/_config.yml @@ -29,6 +29,7 @@ highlighter: rouge # theme: minima plugins: - jekyll-feed + - jekyll-tabs defaults: - scope: diff --git a/_data/nav.yml b/_data/nav.yml index 3c3d3a3f..ebaf403f 100644 --- a/_data/nav.yml +++ b/_data/nav.yml @@ -1,5 +1,5 @@ - name: Getting Started - link: /ontology/start.html + link: /ontology/get-started.html - name: Releases submenuitems: - name: Latest Release diff --git a/_includes/header.html b/_includes/header.html index 02a04e4b..af7ae793 100644 --- a/_includes/header.html +++ b/_includes/header.html @@ -18,6 +18,8 @@ + + diff --git a/_layouts/default.html b/_layouts/default.html index 8193a205..771789ea 100644 --- a/_layouts/default.html +++ b/_layouts/default.html @@ -16,6 +16,7 @@
Learn about CASE's parent organization.
diff --git a/ontology/get-started.md b/ontology/get-started.md new file mode 100644 index 00000000..e15dee1f --- /dev/null +++ b/ontology/get-started.md @@ -0,0 +1,267 @@ +--- +title: Get Started +jumbo_desc: Get started with CASE using code examples. +--- + +### Get Started with CASE + +The full collection of libraries, tools, and documentation for CASE is available on the [CASE GitHub](https://github.com/casework) repository. This guide walks through the anatomy of a CASE graph, full CASE example graph, and how to generate and query CASE graphs. + +### Anatomy of a CASE Graph + +CASE uses JSON-LD which is JSON with linked relationships between objects within the JSON. It contains two top-level keys, `@context` and `@graph`. The `@context` key is a mapping of aliases and namespaces that point to namespaces within the UCO and CASE ontologys. The `@graph` key is an array/list of objects that represent the data being exchanged. + +Each object within the `@graph` key is an Object, which contains at least an `@id` key that is a unique identifier for the object. The `@type` key is the aliased type of the object within the ontology. The available and required properties are defined in the ontology schema. A mimimal example is: + +```json +{ + "@id": "kb:location-4511219e-a924-4ba5-aee7-dfad5a2c9c05", + "@type": "uco-location:Location" +} +``` + + +### Full CASE Example Graph + +A full (basic) example of a CASE JSON-LD output is below: + +```json +{ + "@context": { + "@vocab": "http://example.org/local#", + "kb": "http://example.org/kb/", + "acme": "http://custompb.acme.org/core#", + "uco-core": "https://ontology.unifiedcyberontology.org/uco/core/", + "uco-location": "https://ontology.unifiedcyberontology.org/uco/location/", + "xsd": "http://www.w3.org/2001/XMLSchema#" + }, + "@graph": [ + { + "@id": "kb:location-4511219e-a924-4ba5-aee7-dfad5a2c9c05", + "@type": "uco-location:Location", + "uco-core:hasFacet": [ + { + "@id": "kb:simple-address-facet-59334948-00b9-4370-85b0-4dc8e07f5384", + "@type": "uco-location:SimpleAddressFacet", + "uco-location:locality": "Seattle", + "uco-location:region": "WA", + "uco-location:postalCode": "98052", + "uco-location:street": "20341 Whitworth Institute 405 N. Whitworth" + }, + { + "@id": "kb:acme-internal-location-facet-41fb3158-bbab-404d-97e4-ac61debb71f3", + "@type": [ + "acme:InternalLocationFacet", + "uco-core:Facet" + ], + "acme:floor": 3, + "acme:roomNumber": 345 + } + ] + }, + { + "@id": "kb:location-b579264d-6e30-4055-bf9b-72390364f224", + "@type": "uco-location:Location", + "uco-core:hasFacet": [ + { + "@id": "kb:simple-address-facet-258f169e-1e9c-4936-ba65-eed0f0c60788", + "@type": "uco-location:SimpleAddressFacet", + "uco-location:locality": "Paris", + "uco-location:country": "France", + "uco-location:postalCode": "F-75002", + "uco-location:street": "38 Bad Guy Headquarters st." + }, + { + "@id": "kb:lat-long-coordinates-facet-36126f9c-0273-48fe-ad4d-6a4e2848458f", + "@type": "uco-location:LatLongCoordinatesFacet", + "uco-location:latitude": { + "@type": "xsd:decimal", + "@value": "48.860346" + }, + "uco-location:longitude": { + "@type": "xsd:decimal", + "@value": "2.331199" + } + } + ] + } + ] +} +``` + +Additional examples are available in the [CASE-Examples](https://github.com/casework/CASE-Examples/tree/master/examples/illustrations) repository. This example was copied from [here](https://github.com/casework/CASE-Examples/blob/master/examples/illustrations/location/location.json). + + +### Basic Graph Creation + +{% tabs log %} + +{% tab log Python %} +```python +import json +import uuid + +# Build the base graph dictionary with the context. This must contain all the namespaces used in the graph +graph: dict = { + "@context": { + "kb": "http://example.org/kb/", + "uco-core": "https://ontology.unifiedcyberontology.org/uco/core/", + "uco-location": "https://ontology.unifiedcyberontology.org/uco/location/", + }, + "@graph": [] +} + +# Add an object to the graph +graph["@graph"].append({ + "@id": "kb:location-" + str(uuid.uuid4()), + "@type": "uco-location:Location", + "uco-core:hasFacet": [ + { + "@id": "kb:simple-address-facet-" + str(uuid.uuid4()), + "@type": "uco-location:SimpleAddressFacet", + "uco-location:locality": "Seattle", + "uco-location:region": "WA", + "uco-location:postalCode": "98052", + "uco-location:street": "20341 Whitworth Institute 405 N. Whitworth" + } + ] +}) + +# Write the dictionary to a JSON file +with open('case.jsonld', 'w') as f: + json.dump(graph, f, indent=4) +``` +{% endtab %} + +{% tab log C# %} +``` +{% endtab %} + +{% tab log C# %} +```cs +// TODO +``` +{% endtab %} + +{% tab log Java %} +```java +// TODO +``` +{% endtab %} + +{% endtabs %} + +### Validation Tools + +#### CLI +Once the JSON-LD output is generated, it can be validated for syntactic correctness using the [`case_validate`](https://github.com/casework/CASE-Utilities-Python) tool. The tool is available as a Python package and can be installed using `pip install case-utils`. + +```bash +pip install case-utils +``` + +Then the tool can be run on the generated JSON-LD file which will output any errors or warnings. +```bash +case_validate case.jsonld +``` + +#### Docker + +The `case_validate` tool is also available as a Docker image on [Docker Hub](https://hub.docker.com/r/kchason/case-validator). The container can be run with the following command: + +```shell +docker run --rm \ + -e CASE_PATH="/opt/case/" \ + -e CASE_VERSION="case-1.3.0" \ + -e CASE_EXTENSION_FILTER="jsonld" \ + -v "/path/to/local:/opt/case" \ + kchason/case-validator:latest +``` + +Full usage documentation is available at the `kchason/case-validator` [Docker Hub page](https://hub.docker.com/r/kchason/case-validator). + +#### GitHub Actions + +There is a GitHub Action available to validate CASE graphs in a CI/CD pipeline that are wrappers around the `case_validate` tool which makes it easier to test built graphs from unit and integrated testing frameworks. + +```yaml +- name: CASE Export Validation + uses: kchason/case-validation-action@v2.9.0 + with: + case-path: ./output/ + case-version: "case-1.3.0" + extension-filter: "jsonld" +``` + +Full usage documentation is available at the [GitHub Action Marketplace](https://github.com/marketplace/actions/case-ontology-validator) page for the CASE Ontology Validator. + +#### GitLab CI Component + +There is also GitLab CI component available to validate CASE graphs in a CI/CD pipeline that are wrappers around the `case_validate` tool which makes it easier to test built graphs from unit and integrated testing frameworks. + +```yaml +include: + - component: https://gitlab.com/keith.chason/case-validation-example/case-validate@0.1.0 + inputs: + case-path: tests/data +``` + +Full usage documentation is available at the [GitLab Repository](https://gitlab.com/keith.chason/case-validation-component). + +### Binding/Mapping Libraries + +Several libraries have been developed to assist in the generation of CASE graphs in various programming languages. These libraries provide a more programmatic way to generate CASE graphs using the language's native data structures. These have been categorized between "Bindings" and "Mappings". + +#### Bindings + +These libraries use RDF graphs to manage the CASE graph data. They provide a more direct mapping to the RDF data model and are more closely aligned with the underlying ontology but can be more resource intensive. + +| Language | Library | Repository | +|----------|----------|------------| +| C# | [CipherTech.CASE.Bindings](https://www.nuget.org/packages/CipherTech.CASE.Bindings) | [https://github.com/ciphertechsolutions/CASE-Bindings-CSharp](https://github.com/ciphertechsolutions/CASE-Bindings-CSharp) | + +#### Mappings + +These libraries use native data structures to manage the CASE graph data. They provide a more programmatic way to generate CASE graphs using the language's native data structures and are then serialized into JSON-LD. + +| Language | Library | Repository | +|----------|----------|------------| +| Python | [case-mapping](https://pypi.org/project/case-mapping/) | [https://github.com/casework/CASE-Mapping-Python](https://github.com/casework/CASE-Mapping-Python) | + + +### Full CASE Concepts + +The rendered documentation for the CASE Ontology, which contains the list of all classes and properties, is available at [https://ontology.caseontology.org](https://ontology.caseontology.org/documentation/index.html). + +All of the concepts used in CASE and UCO are identified with IRIs, which redirect to the concept's documentation when visited in a browser. See for example the location classes used above: + +* [`uco-location:Location`](https://ontology.unifiedcyberontology.org/uco/location/Location) +* [`uco-location:LatLongCoordinatesFacet`](https://ontology.unifiedcyberontology.org/uco/location/LatLongCoordinatesFacet) +* [`uco-location:SimpleAddressFacet`](https://ontology.unifiedcyberontology.org/uco/location/SimpleAddressFacet) + + +### Query CASE Graphs + +{% tabs log %} + +{% tab log Python %} +```python +# TODO +``` +{% endtab %} + +{% tab log C# %} +```cs +// TODO +``` +{% endtab %} + +{% tab log Java %} +```java +// TODO +``` +{% endtab %} + +{% endtabs %} + +A full set of examples for querying CASE graphs and converting them to a GeoJSON output format in several programming languages is available in the [CASE-Examples-Conversion](https://github.com/casework/CASE-Examples-Conversion) repository.