Skip to content

Commit

Permalink
feat (core): Graphviz! (re. enola-dev#502)
Browse files Browse the repository at this point in the history
  • Loading branch information
vorburger committed Aug 10, 2024
1 parent cc25e39 commit 9e78a1e
Show file tree
Hide file tree
Showing 34 changed files with 693 additions and 72 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ trim_trailing_whitespace = true
insert_final_newline = false
max_line_length = unset

[*.expected*]
max_line_length = unset

[*.md]
indent_size = unset
# See, and must match, the .markdownlint.yaml MD013: line_length
Expand Down
2 changes: 2 additions & 0 deletions ToDo.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

## High Priority (Next Features)

1. Merge this with [`ToDo.yaml`](ToDo.yaml)

1. Support top-level `namespace: "demo"` in `docs/use/library/model.textproto` and rm others

### UI
Expand Down
128 changes: 128 additions & 0 deletions ToDo.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
# SPDX-License-Identifier: Apache-2.0
#
# Copyright 2024 The Enola <https://enola.dev> Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

label: Enola.dev ToDo
type: https://enola.dev/todo/List
items:
- GraphViz Diagrams: &graphviz
owner: vorburger
target: 2024-08-11
status: WIP
tags: [visualization, ui, docgen, rosetta]
items:
- ? Rosetta `*.gv` GraphViz
- HTML UI GraphViz:
links: ["https://visjs.github.io/vis-network/docs/network/#importDot"]
- ? Document GraphViz on https://docs.enola.dev/use/rosetta/ via file:docs/use/rosetta/index.md
- ? Document GraphViz in Tutorial via "Graphs" section
- ? Use GraphViz to put big graph on https://docs.enola.dev/models/
- ? Use shorter IDs in Graphviz *.gv; generated numerically ad-hoc, not GUID

- Re-design Thing Java API:
description: Factor out is/Not/Link from GraphvizGenerator; re-think API.

- Timeline Diagrams:
tags: [visualization, ui, docgen, rosetta]
depends: [*graphviz]

- Meta YAML reader:
status: TBD

- Inference with LLM:
description: What files are in directory xyz? Is abc under xyz, even indirectly?
tags: [ml]

- Document UI in Tutorial:
tags: [doc]

- Clean Up all old model related code & doc:
tags: [clean, doc]

- ? Queries with SparQL

- ? Persistent Store

- Kubernetes Model:
target: 2024-09-15

- Meta Java Code Generator: &metaJavaCodegen

- Remove (?) LinkML:
tags: [clean]

- Markdown Model: &modelMarkdown
links: ["https://github.com/enola-dev/enola/labels/model%2Fmarkdown"]
depends: [*metaJavaCodegen]

- Implement ToDo Model: &modelToDo
links: https://github.com/enola-dev/dora/tree/main/TODO
description: Make this very file (ToDo.yaml) `--load`-able, and visualizable as Graph, and DocGen-able as MD.
tags: [model]
items:
- ? Write `todo.esch.yaml` & `todo-context.jsonld` in `models/enola.dev/todo/`

- Validation:
depends: [*metaJavaCodegen]

- ? Merge this `ToDo.yaml` with [`ToDo.md`](ToDo.md)

- Make Rosetta --load multiple inputs instead of --in: &rosettaLoad

- Unify DocGen into Rosetta:
tags: [ui, docgen, rosetta]
depends: [*rosettaLoad]

- Unify UI with Rosetta:
tags: [ui, rosetta]

- Replace TLC for Classes with @Inject DI:
description:
With [Dagger](https://dagger.dev)? But how suitable is it for different *Test VS e.g. CLI set-up? (Keep TLC for
per-request Locale, TZ, etc.)
tags: [ui, rosetta]

- JetBrains Gateway with Dev Container:
links: https://www.jetbrains.com/help/idea/connect-to-devcontainer.html
tags: [contributors, doc]

- Document Enola Things YAML/JSON/HTML (?) Format: &docRosettaThingsYAML
description: java:RosettaTest#testTurtleToThings should be documented in file:docs/use/rosetta/index.md
tags: [doc]

- Close all [open old PRs](https://github.com/enola-dev/enola/pulls):
tags: [contributors]

- Gephi/SigmaJS Network Graph Format:
depends: [*graphviz]
tags: [visualization, ui, docgen, rosetta]
links:
- https://www.sigmajs.org
- https://docs.enola.dev/concepts/other/#visualization
- https://visjs.github.io/vis-network/docs/network/#importGephi

- Graphviz in Java fully integrated into Enola binary:
links:
- https://github.com/jamisonjiang/graph-support
- https://github.com/nidi3/graphviz-java

tags:
- clean
- doc
- docgen
- ui
- rosetta
- model
- visualization
17 changes: 8 additions & 9 deletions java/dev/enola/cli/CommandWithModel.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

import dev.enola.common.context.TLC;
import dev.enola.common.io.iri.URIs;
import dev.enola.common.io.iri.namespace.NamespaceConverter;
import dev.enola.common.io.iri.namespace.NamespaceConverterWithRepository;
import dev.enola.common.io.iri.namespace.NamespaceRepositoryEnolaDefaults;
import dev.enola.common.io.metadata.MetadataProvider;
Expand All @@ -36,7 +37,6 @@
import dev.enola.data.ProviderFromIRI;
import dev.enola.data.Repository;
import dev.enola.datatype.DatatypeRepository;
import dev.enola.datatype.DatatypeRepositoryBuilder;
import dev.enola.datatype.Datatypes;
import dev.enola.thing.ThingMetadataProvider;
import dev.enola.thing.io.Loader;
Expand Down Expand Up @@ -99,6 +99,11 @@ public final void run() throws Exception {
DatatypeRepository dtr = Datatypes.DTR;
ctx.push(DatatypeRepository.class, dtr);

// TODO This must be configurable & dynamic...
var namespaceRepo = NamespaceRepositoryEnolaDefaults.INSTANCE;
var namespaceConverter = new NamespaceConverterWithRepository(namespaceRepo);
ctx.push(NamespaceConverter.class, namespaceConverter);

ThingMemoryRepositoryROBuilder store = new ThingMemoryRepositoryROBuilder();

// TODO Explicitly add UriIntoThingConverter, depending on CLI feature flags
Expand Down Expand Up @@ -160,15 +165,9 @@ public final void run() throws Exception {

// TODO Move this to class EnolaProvider?
protected MetadataProvider getMetadataProvider(ProviderFromIRI<Thing> thingProvider) {
// TODO look up in global repository!
var datatypeRepository = new DatatypeRepositoryBuilder().build();

// TODO This must be configurable & dynamic...
var namespaceRepo = NamespaceRepositoryEnolaDefaults.INSTANCE;
var namespaceConverter = new NamespaceConverterWithRepository(namespaceRepo);

return new ThingMetadataProvider(
new ThingProviderAdapter(thingProvider, datatypeRepository), namespaceConverter);
new ThingProviderAdapter(thingProvider, DatatypeRepository.CTX),
NamespaceConverter.CTX);
}

// TODO Pass only the EnolaServiceBlockingStub through, remove the EntityKindRepository from
Expand Down
15 changes: 15 additions & 0 deletions java/dev/enola/common/io/iri/namespace/NamespaceConverter.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
*/
package dev.enola.common.io.iri.namespace;

import dev.enola.common.context.TLC;

/**
* NamespaceConverter converts "compact" <a
* href="https://en.m.wikipedia.org/wiki/CURIE">CURIE</a>-like IRIs (i.e. an IRI with a short
Expand All @@ -32,4 +34,17 @@ public interface NamespaceConverter {
String toCURIE(String iri);

String toIRI(String curie);

NamespaceConverter CTX =
new NamespaceConverter() {
@Override
public String toCURIE(String iri) {
return TLC.get(NamespaceConverter.class).toCURIE(iri);
}

@Override
public String toIRI(String curie) {
return TLC.get(NamespaceConverter.class).toIRI(curie);
}
};
}
45 changes: 45 additions & 0 deletions java/dev/enola/common/io/testlib/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# SPDX-License-Identifier: Apache-2.0
#
# Copyright 2023 The Enola <https://enola.dev> Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bazel:junit.bzl", "junit_tests")

java_library(
name = "testlib",
srcs = glob(
["**/*.java"],
exclude = ["**/*Test.java"],
),
visibility = ["//:__subpackages__"],
deps = [
"//java/dev/enola/common/io",
"//java/dev/enola/common/yamljson",
"@maven//:com_google_errorprone_error_prone_annotations",
"@maven//:com_google_guava_guava",
"@maven//:com_google_truth_truth",
"@maven//:org_jspecify_jspecify",
],
)

junit_tests(
name = "tests",
srcs = glob(["**/*Test.java"]),
deps = [
":testlib",
"//java/dev/enola/common/io",
"@maven//:org_jspecify_jspecify",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.enola.rdf;
package dev.enola.common.io.testlib;

import static com.google.common.truth.Truth.assertAbout;

Expand All @@ -29,8 +29,6 @@

public final class ResourceSubject extends Subject {

// TODO Move this class to a //common/testlib

public static ResourceSubject assertThat(ReadableResource actual) {
return assertAbout(resources()).that(actual);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
* limitations under the License.
*/
@NullMarked
package dev.enola.common.yamljson.test;
package dev.enola.common.io.testlib;

import org.jspecify.annotations.NullMarked;
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ load("@rules_java//java:defs.bzl", "java_library")
load("//tools/bazel:junit.bzl", "junit_tests")

java_library(
name = "test",
name = "testlib",
srcs = glob(
["*.java"],
exclude = ["*Test.java"],
Expand All @@ -37,6 +37,6 @@ junit_tests(
name = "tests",
srcs = glob(["**/*Test.java"]),
deps = [
":test",
":testlib",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.enola.common.yamljson.test;
package dev.enola.common.yamljson.testlib;

import org.yaml.snakeyaml.DumperOptions;
import org.yaml.snakeyaml.introspector.Property;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dev.enola.common.yamljson.test;
package dev.enola.common.yamljson.testlib;

import com.google.common.net.MediaType;
import com.google.common.truth.Truth;
Expand Down
21 changes: 21 additions & 0 deletions java/dev/enola/common/yamljson/testlib/package-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/*
* SPDX-License-Identifier: Apache-2.0
*
* Copyright 2024 The Enola <https://enola.dev> Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
@NullMarked
package dev.enola.common.yamljson.testlib;

import org.jspecify.annotations.NullMarked;
3 changes: 3 additions & 0 deletions java/dev/enola/core/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,10 @@ junit_tests(
# "//connectors/demo",
# "//connectors/demo:demo_java_proto",
"//java/dev/enola/common/concurrent",
"//java/dev/enola/common/context",
"//java/dev/enola/common/convert",
"//java/dev/enola/common/io",
"//java/dev/enola/common/io/testlib",
"//java/dev/enola/common/protobuf",
"//java/dev/enola/common/yamljson", # TODO Remove this once dependencies are cleaned up
"//java/dev/enola/core",
Expand All @@ -210,6 +212,7 @@ junit_tests(
"//java/dev/enola/core:core_java_proto",
"//java/dev/enola/data",
"//java/dev/enola/rdf",
"//java/dev/enola/thing/gen",
"//java/dev/enola/thing:thing_java",
"//java/dev/enola/thing:thing_java_proto",
"//test",
Expand Down
5 changes: 5 additions & 0 deletions java/dev/enola/core/meta/docgen/GraphvizGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@
import java.util.stream.Collectors;

class GraphvizGenerator {

// NB: This is the (old) GraphvizGenerator for the *OLD* (EntityKind) model;
// the (new) GraphvizGenerator for Things is in dev.enola.thing.gen.graphviz!
// TODO Remove this, as part of the overall EntityKind etc. clean-up.

static void renderGraphviz(Iterable<EntityKind> kinds, Appendable md) throws IOException {
md.append("```dot\n");
md.append("digraph {\n");
Expand Down
Loading

0 comments on commit 9e78a1e

Please sign in to comment.