Skip to content

Commit

Permalink
feat (cli): get --format=Graphviz
Browse files Browse the repository at this point in the history
  • Loading branch information
vorburger committed Oct 28, 2024
1 parent cc5faf0 commit 28fafa5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 5 deletions.
2 changes: 2 additions & 0 deletions docs/concepts/other.md
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ Vaguely related other such tools include:

* [`com.google.common.graph`](https://github.com/google/guava/wiki/GraphsExplained) Java API
* [JGraphT](https://jgrapht.org) Java Library
* [NetworkX](https://networkx.org/) Python package

[Semantic Triple](https://en.wikipedia.org/wiki/Semantic_triple) Java libraries ([comparison](https://github.com/trellis-ldp/trellis/issues/358)):

Expand Down Expand Up @@ -189,6 +190,7 @@ Some [db-engines.com](https://db-engines.com/en/ranking/rdf+store):

### GraphML DB

* [ArangoDB](https://arangodb.com) #GraphML #opensource #commercial
* [LlamaIndex](https://www.llamaindex.ai) #GraphML #opensource? #ToDo
* [varunshenoy/GraphGPT](https://github.com/varunshenoy/GraphGPT) #GraphML #opensource #demo
* [HKUDS/GraphGPT](https://github.com/HKUDS/GraphGPT) #GraphML #opensource #paper
Expand Down
31 changes: 26 additions & 5 deletions java/dev/enola/cli/CommandWithIRI.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,12 @@
import dev.enola.core.view.EnolaMessages;
import dev.enola.rdf.io.RdfWriterConverter;
import dev.enola.rdf.proto.ProtoThingRdfConverter;
import dev.enola.thing.gen.graphviz.GraphvizGenerator;
import dev.enola.thing.message.ProtoThings;
import dev.enola.thing.metadata.ThingMetadataProvider;
import dev.enola.thing.proto.Thing;
import dev.enola.thing.proto.Things;
import dev.enola.web.EnolaThingProvider;

import picocli.CommandLine;

Expand All @@ -52,9 +57,12 @@ public abstract class CommandWithIRI extends CommandWithModelAndOutput {
private WritableResource resource;
private TypeRegistryWrapper typeRegistryWrapper;
protected EnolaMessages enolaMessages;
private ThingMetadataProvider thingMetadataProvider;

@Override
protected final void run(EnolaServiceBlockingStub service) throws Exception {
thingMetadataProvider = getMetadataProvider(new EnolaThingProvider(service));

var gfdsr = GetFileDescriptorSetRequest.newBuilder().build();
var fds = service.getFileDescriptorSet(gfdsr).getProtos();
typeRegistryWrapper = TypeRegistryWrapper.from(fds);
Expand All @@ -76,11 +84,24 @@ protected final void run(EnolaServiceBlockingStub service) throws Exception {
protected abstract void run(EnolaServiceBlockingStub service, String eri) throws Exception;

protected void write(Message thing) throws IOException {
if (thing instanceof Thing protoThing
&& (Format.Turtle.equals(format) || Format.JSONLD.equals(format))) {
var model = new ProtoThingRdfConverter().convert(protoThing);
new RdfWriterConverter().convertIntoOrThrow(model, resource);
if (thing instanceof Thing protoThing) {
if (Format.Turtle.equals(format) || Format.JSONLD.equals(format)) {
var model = new ProtoThingRdfConverter().convert(protoThing);
new RdfWriterConverter().convertIntoOrThrow(model, resource);
return;
}
}

if (thing instanceof Things protoThings) {
if (Format.Graphviz.equals(format)) {
var javaThings = ProtoThings.proto2java(protoThings.getThingsList());
new GraphvizGenerator(thingMetadataProvider)
.convertIntoOrThrow(javaThings, resource);
return;
}
}

} else new ProtoIO(typeRegistryWrapper.get()).write(thing, resource);
// Otherwise
new ProtoIO(typeRegistryWrapper.get()).write(thing, resource);
}
}
4 changes: 4 additions & 0 deletions java/dev/enola/cli/Format.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,15 @@

import dev.enola.common.protobuf.ProtobufMediaTypes;
import dev.enola.rdf.io.RdfMediaTypes;
import dev.enola.thing.gen.graphviz.GraphvizMediaType;

public enum Format {
Turtle,

JSONLD,

Graphviz,

TextProto,

ProtoYAML,
Expand All @@ -39,6 +42,7 @@ MediaType toMediaType() {
return switch (this) {
case Turtle -> RdfMediaTypes.TURTLE;
case JSONLD -> RdfMediaTypes.JSON_LD;
case Graphviz -> GraphvizMediaType.GV;

case TextProto -> ProtobufMediaTypes.PROTOBUF_TEXTPROTO_UTF_8;
case ProtoYAML -> ProtobufMediaTypes.PROTOBUF_YAML_UTF_8;
Expand Down

0 comments on commit 28fafa5

Please sign in to comment.