diff --git a/pom.xml b/pom.xml index 8c7cb76..1b4591b 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 org.geneontology obographs - 0.2.0 + 0.2.1 jar ${project.groupId}:${project.artifactId} Reference implementation for Obo Graphs @@ -168,6 +168,15 @@ org.apache.maven.plugins maven-javadoc-plugin 2.9.1 + + ch.raffael.doclets.pegdown.PegdownDoclet + + ch.raffael.pegdown-doclet + pegdown-doclet + 1.1 + + true + attach-javadocs @@ -177,21 +186,6 @@ - - - maven-javadoc-plugin - 2.9 - - ch.raffael.doclets.pegdown.PegdownDoclet - - ch.raffael.pegdown-doclet - pegdown-doclet - 1.1 - - true - - - diff --git a/src/main/java/org/geneontology/obographs/io/OgJsonReader.java b/src/main/java/org/geneontology/obographs/io/OgJsonReader.java index 1d49ab0..6d92f93 100644 --- a/src/main/java/org/geneontology/obographs/io/OgJsonReader.java +++ b/src/main/java/org/geneontology/obographs/io/OgJsonReader.java @@ -1,27 +1,26 @@ package org.geneontology.obographs.io; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.geneontology.obographs.model.GraphDocument; + import java.io.File; import java.io.IOException; import java.io.InputStream; -import org.geneontology.obographs.model.Graph; - -import com.fasterxml.jackson.databind.ObjectMapper; - public class OgJsonReader { - public static Graph readFile(String fileName) throws IOException { + public static GraphDocument readFile(String fileName) throws IOException { return readFile(new File(fileName)); } - public static Graph readFile(File file) throws IOException { + public static GraphDocument readFile(File file) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); - return objectMapper.readValue(file, Graph.class); + return objectMapper.readValue(file, GraphDocument.class); } - public static Graph readInputStream(InputStream stream) throws IOException { + public static GraphDocument readInputStream(InputStream stream) throws IOException { ObjectMapper objectMapper = new ObjectMapper(); - return objectMapper.readValue(stream, Graph.class); + return objectMapper.readValue(stream, GraphDocument.class); } } diff --git a/src/main/java/org/geneontology/obographs/model/Edge.java b/src/main/java/org/geneontology/obographs/model/Edge.java index ab53b51..2066d65 100644 --- a/src/main/java/org/geneontology/obographs/model/Edge.java +++ b/src/main/java/org/geneontology/obographs/model/Edge.java @@ -1,6 +1,8 @@ package org.geneontology.obographs.model; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; /** * An edge connects two nodes via a predicate @@ -8,6 +10,7 @@ * @author cjm * */ +@JsonDeserialize(builder = Edge.Builder.class) public class Edge implements NodeOrEdge { private Edge(Builder builder) { @@ -48,7 +51,15 @@ public String getObj() { return obj; } - + @Override + public String toString() { + return "Edge{" + + "sub='" + sub + '\'' + + ", pred='" + pred + '\'' + + ", obj='" + obj + '\'' + + ", meta=" + meta + + '}'; + } /** * @return the meta @@ -90,6 +101,7 @@ public Builder meta(Meta meta) { return this; } + @JsonCreator public Edge build() { return new Edge(this); } diff --git a/src/main/java/org/geneontology/obographs/model/Graph.java b/src/main/java/org/geneontology/obographs/model/Graph.java index 16f86c8..f42f8dd 100644 --- a/src/main/java/org/geneontology/obographs/model/Graph.java +++ b/src/main/java/org/geneontology/obographs/model/Graph.java @@ -1,13 +1,14 @@ package org.geneontology.obographs.model; -import java.util.List; - +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.geneontology.obographs.model.axiom.DomainRangeAxiom; import org.geneontology.obographs.model.axiom.EquivalentNodesSet; import org.geneontology.obographs.model.axiom.LogicalDefinitionAxiom; import org.geneontology.obographs.model.axiom.PropertyChainAxiom; -import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; /** * A graph object holds a collection of nodes and edges @@ -33,6 +34,7 @@ * @author cjm * */ +@JsonDeserialize(builder = Graph.Builder.class) public class Graph { private Graph(Builder builder) { @@ -139,6 +141,20 @@ public List getPropertyChainAxioms() { } + @Override + public String toString() { + return "Graph{" + + "nodes=" + nodes + + ", edges=" + edges + + ", id='" + id + '\'' + + ", lbl='" + lbl + '\'' + + ", meta=" + meta + + ", equivalentNodesSets=" + equivalentNodesSets + + ", logicalDefinitionAxioms=" + logicalDefinitionAxioms + + ", domainRangeAxioms=" + domainRangeAxioms + + ", propertyChainAxioms=" + propertyChainAxioms + + '}'; + } public static class Builder { @@ -202,6 +218,7 @@ public Builder domainRangeAxioms(List domainRangeAxioms) { return this; } + @JsonCreator public Graph build() { return new Graph(this); } diff --git a/src/main/java/org/geneontology/obographs/model/GraphDocument.java b/src/main/java/org/geneontology/obographs/model/GraphDocument.java index c79cea6..be361c2 100644 --- a/src/main/java/org/geneontology/obographs/model/GraphDocument.java +++ b/src/main/java/org/geneontology/obographs/model/GraphDocument.java @@ -1,8 +1,10 @@ package org.geneontology.obographs.model; -import java.util.List; - +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +import java.util.List; /** * Holds a collection of graphs, plus document-level metadata @@ -23,6 +25,7 @@ * @author cjm * */ +@JsonDeserialize(builder = GraphDocument.Builder.class) public class GraphDocument { private GraphDocument(Builder builder) { @@ -61,9 +64,14 @@ public Meta getMeta() { } - - - + @Override + public String toString() { + return "GraphDocument{" + + "graphs=" + graphs + + ", meta=" + meta + + ", context=" + context + + '}'; + } public static class Builder { @@ -71,11 +79,9 @@ public static class Builder { private Meta meta; @JsonProperty private List graphs; - @JsonProperty + @JsonProperty("@context") private Object context; - - public Builder meta(Meta meta) { this.meta = meta; return this; @@ -89,6 +95,7 @@ public Builder context(Object context) { return this; } + @JsonCreator public GraphDocument build() { return new GraphDocument(this); } diff --git a/src/main/java/org/geneontology/obographs/model/Meta.java b/src/main/java/org/geneontology/obographs/model/Meta.java index d6a498a..0856fe1 100644 --- a/src/main/java/org/geneontology/obographs/model/Meta.java +++ b/src/main/java/org/geneontology/obographs/model/Meta.java @@ -1,7 +1,9 @@ package org.geneontology.obographs.model; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.geneontology.obographs.model.meta.*; import java.util.ArrayList; @@ -25,6 +27,7 @@ * @author cjm * */ +@JsonDeserialize(builder = Meta.Builder.class) public class Meta { private Meta(Builder builder) { @@ -107,6 +110,20 @@ public Boolean getDeprecated() { return deprecated; } + @Override + public String toString() { + return "Meta{" + + "definition=" + definition + + ", comments=" + comments + + ", subsets=" + subsets + + ", xrefs=" + xrefs + + ", synonyms=" + synonyms + + ", basicPropertyValues=" + basicPropertyValues + + ", version='" + version + '\'' + + ", deprecated=" + deprecated + + '}'; + } + public static class Builder { @JsonProperty @@ -205,6 +222,7 @@ public Builder deprecated(Boolean deprecated) { } + @JsonCreator public Meta build() { return new Meta(this); } diff --git a/src/main/java/org/geneontology/obographs/model/Node.java b/src/main/java/org/geneontology/obographs/model/Node.java index 2a69290..29bcde1 100644 --- a/src/main/java/org/geneontology/obographs/model/Node.java +++ b/src/main/java/org/geneontology/obographs/model/Node.java @@ -1,6 +1,8 @@ package org.geneontology.obographs.model; +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; /** * A graph node corresponds to a class, individual or property @@ -19,6 +21,7 @@ * @author cjm * */ +@JsonDeserialize(builder = Node.Builder.class) public class Node implements NodeOrEdge { public enum RDFTYPES { CLASS, INDIVIDUAL, PROPERTY }; @@ -77,11 +80,21 @@ public Meta getMeta() { return meta; } - public static class Builder { + @Override + public String toString() { + return "Node{" + + "id='" + id + '\'' + + ", label='" + label + '\'' + + ", meta=" + meta + + ", type=" + type + + '}'; + } + + public static class Builder { @JsonProperty private String id; - @JsonProperty + @JsonProperty("lbl") private String label; @JsonProperty private Meta meta; @@ -108,6 +121,7 @@ public Builder type(RDFTYPES type) { return this; } + @JsonCreator public Node build() { return new Node(this); } diff --git a/src/main/java/org/geneontology/obographs/model/axiom/AbstractAxiom.java b/src/main/java/org/geneontology/obographs/model/axiom/AbstractAxiom.java index 7abae99..115fcc0 100644 --- a/src/main/java/org/geneontology/obographs/model/axiom/AbstractAxiom.java +++ b/src/main/java/org/geneontology/obographs/model/axiom/AbstractAxiom.java @@ -1,11 +1,7 @@ package org.geneontology.obographs.model.axiom; -import java.util.Set; - -import org.geneontology.obographs.model.Meta; -import org.geneontology.obographs.model.axiom.EquivalentNodesSet.Builder; - import com.fasterxml.jackson.annotation.JsonProperty; +import org.geneontology.obographs.model.Meta; public abstract class AbstractAxiom implements Axiom { @@ -31,7 +27,7 @@ public static class Builder { @JsonProperty private Meta meta; - + public Builder meta(Meta meta) { this.meta = meta; return this; diff --git a/src/main/java/org/geneontology/obographs/model/axiom/AbstractExpression.java b/src/main/java/org/geneontology/obographs/model/axiom/AbstractExpression.java index 8588b28..b089421 100644 --- a/src/main/java/org/geneontology/obographs/model/axiom/AbstractExpression.java +++ b/src/main/java/org/geneontology/obographs/model/axiom/AbstractExpression.java @@ -1,10 +1,5 @@ package org.geneontology.obographs.model.axiom; -import org.geneontology.obographs.model.Meta; -import org.geneontology.obographs.model.axiom.AbstractAxiom.Builder; - -import com.fasterxml.jackson.annotation.JsonProperty; - public class AbstractExpression implements Expression { protected AbstractExpression(Builder builder) { @@ -12,8 +7,5 @@ protected AbstractExpression(Builder builder) { public static class Builder { - - - } } diff --git a/src/main/java/org/geneontology/obographs/model/axiom/DomainRangeAxiom.java b/src/main/java/org/geneontology/obographs/model/axiom/DomainRangeAxiom.java index 92f68bc..ca7b78d 100644 --- a/src/main/java/org/geneontology/obographs/model/axiom/DomainRangeAxiom.java +++ b/src/main/java/org/geneontology/obographs/model/axiom/DomainRangeAxiom.java @@ -1,14 +1,14 @@ package org.geneontology.obographs.model.axiom; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.Set; - +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.geneontology.obographs.model.Edge; import org.geneontology.obographs.model.Meta; -import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Collections; +import java.util.HashSet; +import java.util.Set; /** * This combined ObjectPropertyDomain, ObjectPropertyRange, and some AllValuesFrom expressions into a single convenience structure @@ -17,6 +17,7 @@ * @author cjm * */ +@JsonDeserialize(builder = DomainRangeAxiom.Builder.class) public class DomainRangeAxiom extends AbstractAxiom { private DomainRangeAxiom(Builder builder) { @@ -137,13 +138,13 @@ public Builder addAllValuesFrom(Edge edge) { allValuesFromEdges = new HashSet<>(); this.allValuesFromEdges.add(edge); return this; - } + + @JsonCreator public DomainRangeAxiom build() { return new DomainRangeAxiom(this); } - } diff --git a/src/main/java/org/geneontology/obographs/model/axiom/EquivalentNodesSet.java b/src/main/java/org/geneontology/obographs/model/axiom/EquivalentNodesSet.java index a634fbb..192fa88 100644 --- a/src/main/java/org/geneontology/obographs/model/axiom/EquivalentNodesSet.java +++ b/src/main/java/org/geneontology/obographs/model/axiom/EquivalentNodesSet.java @@ -1,10 +1,11 @@ package org.geneontology.obographs.model.axiom; -import java.util.Set; - +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.geneontology.obographs.model.Meta; -import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.Set; /** * A set of nodes that all stand in a mutual equivalence or identity relationship to one another @@ -15,6 +16,7 @@ * @author cjm * */ +@JsonDeserialize(builder = EquivalentNodesSet.Builder.class) public class EquivalentNodesSet extends AbstractAxiom { private EquivalentNodesSet(Builder builder) { @@ -64,7 +66,8 @@ public Builder nodeIds(Set nodeIds) { this.nodeIds = nodeIds; return this; } - + + @JsonCreator public EquivalentNodesSet build() { return new EquivalentNodesSet(this); } diff --git a/src/main/java/org/geneontology/obographs/model/axiom/ExistentialRestrictionExpression.java b/src/main/java/org/geneontology/obographs/model/axiom/ExistentialRestrictionExpression.java index 2691d50..095f184 100644 --- a/src/main/java/org/geneontology/obographs/model/axiom/ExistentialRestrictionExpression.java +++ b/src/main/java/org/geneontology/obographs/model/axiom/ExistentialRestrictionExpression.java @@ -1,10 +1,8 @@ package org.geneontology.obographs.model.axiom; -import java.util.Set; - -import org.geneontology.obographs.model.Meta; - +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; /** * Corresponds to an axiom of the form C = X1 and ... and Xn, @@ -14,6 +12,7 @@ * @author cjm * */ +@JsonDeserialize(builder = ExistentialRestrictionExpression.Builder.class) public class ExistentialRestrictionExpression extends AbstractExpression { private ExistentialRestrictionExpression(Builder builder) { @@ -64,6 +63,7 @@ public Builder fillerId(String fillerId) { return this; } + @JsonCreator public ExistentialRestrictionExpression build() { return new ExistentialRestrictionExpression(this); } diff --git a/src/main/java/org/geneontology/obographs/model/axiom/LogicalDefinitionAxiom.java b/src/main/java/org/geneontology/obographs/model/axiom/LogicalDefinitionAxiom.java index f5cc97b..8ff5d87 100644 --- a/src/main/java/org/geneontology/obographs/model/axiom/LogicalDefinitionAxiom.java +++ b/src/main/java/org/geneontology/obographs/model/axiom/LogicalDefinitionAxiom.java @@ -1,11 +1,11 @@ package org.geneontology.obographs.model.axiom; -import java.util.List; -import java.util.Set; - +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; import org.geneontology.obographs.model.Meta; -import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; /** * Corresponds to an axiom of the form C = X1 and ... and Xn, @@ -15,6 +15,7 @@ * @author cjm * */ +@JsonDeserialize(builder = LogicalDefinitionAxiom.Builder.class) public class LogicalDefinitionAxiom extends AbstractAxiom { private LogicalDefinitionAxiom(Builder builder) { @@ -81,7 +82,8 @@ public Builder restrictions(List restrictions) this.restrictions = restrictions; return this; } - + + @JsonCreator public LogicalDefinitionAxiom build() { return new LogicalDefinitionAxiom(this); } diff --git a/src/main/java/org/geneontology/obographs/model/axiom/PropertyChainAxiom.java b/src/main/java/org/geneontology/obographs/model/axiom/PropertyChainAxiom.java index e246c75..865f5a9 100644 --- a/src/main/java/org/geneontology/obographs/model/axiom/PropertyChainAxiom.java +++ b/src/main/java/org/geneontology/obographs/model/axiom/PropertyChainAxiom.java @@ -1,15 +1,10 @@ package org.geneontology.obographs.model.axiom; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -import org.geneontology.obographs.model.Edge; -import org.geneontology.obographs.model.Meta; - +import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; + +import java.util.List; /** * P <- P1 ... Pn @@ -18,6 +13,7 @@ * @author cjm * */ +@JsonDeserialize(builder = PropertyChainAxiom.Builder.class) public class PropertyChainAxiom extends AbstractAxiom { private PropertyChainAxiom(Builder builder) { @@ -63,7 +59,8 @@ public Builder chainPredicateIds(List chainPredicateIds) { this.chainPredicateIds = chainPredicateIds; return this; } - + + @JsonCreator public PropertyChainAxiom build() { return new PropertyChainAxiom(this); } diff --git a/src/main/java/org/geneontology/obographs/model/meta/AbstractPropertyValue.java b/src/main/java/org/geneontology/obographs/model/meta/AbstractPropertyValue.java index 1ec918f..c6e92a1 100644 --- a/src/main/java/org/geneontology/obographs/model/meta/AbstractPropertyValue.java +++ b/src/main/java/org/geneontology/obographs/model/meta/AbstractPropertyValue.java @@ -1,11 +1,9 @@ package org.geneontology.obographs.model.meta; -import java.util.Collection; -import java.util.List; - +import com.fasterxml.jackson.annotation.JsonProperty; import org.geneontology.obographs.model.Meta; -import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; public abstract class AbstractPropertyValue implements PropertyValue { @@ -18,10 +16,14 @@ protected AbstractPropertyValue(Builder builder) { xrefs = builder.xrefs; } - private final String pred; + @JsonProperty + private final String pred; + @JsonProperty private final String val; + @JsonProperty private final List xrefs; - private final Meta meta; + @JsonProperty + private final Meta meta; @@ -62,9 +64,17 @@ public Meta getMeta() { return meta; } + @Override + public String toString() { + return "AbstractPropertyValue{" + + "pred='" + pred + '\'' + + ", val='" + val + '\'' + + ", xrefs=" + xrefs + + ", meta=" + meta + + '}'; + } - - public static class Builder { + public static class Builder { @JsonProperty private String pred; diff --git a/src/main/java/org/geneontology/obographs/model/meta/BasicPropertyValue.java b/src/main/java/org/geneontology/obographs/model/meta/BasicPropertyValue.java index 6641df6..fea6664 100644 --- a/src/main/java/org/geneontology/obographs/model/meta/BasicPropertyValue.java +++ b/src/main/java/org/geneontology/obographs/model/meta/BasicPropertyValue.java @@ -1,40 +1,40 @@ package org.geneontology.obographs.model.meta; -import java.util.List; - -import org.geneontology.obographs.model.Meta; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import com.fasterxml.jackson.annotation.JsonProperty; +import java.util.List; /** * A generic {@link PropertyValue} that is not explicitly modeled - * - * @author cjm * + * @author cjm */ -public class BasicPropertyValue extends AbstractPropertyValue implements PropertyValue { - - private BasicPropertyValue(Builder builder) { - super(builder); - } +@JsonDeserialize(builder = BasicPropertyValue.Builder.class) +public class BasicPropertyValue extends AbstractPropertyValue { + private BasicPropertyValue(Builder builder) { + super(builder); + } - public static class Builder extends AbstractPropertyValue.Builder { + public static class Builder extends AbstractPropertyValue.Builder { public Builder pred(String pred) { return (Builder) super.pred(pred); } + public Builder val(String val) { return (Builder) super.val(val); } + public Builder xrefs(List xrefs) { return (Builder) super.xrefs(xrefs); } - + @JsonCreator public BasicPropertyValue build() { - return new BasicPropertyValue(this); + return new BasicPropertyValue(this); } } - + } diff --git a/src/main/java/org/geneontology/obographs/model/meta/DefinitionPropertyValue.java b/src/main/java/org/geneontology/obographs/model/meta/DefinitionPropertyValue.java index 3c9d287..ac57e49 100644 --- a/src/main/java/org/geneontology/obographs/model/meta/DefinitionPropertyValue.java +++ b/src/main/java/org/geneontology/obographs/model/meta/DefinitionPropertyValue.java @@ -1,19 +1,20 @@ package org.geneontology.obographs.model.meta; -import java.util.List; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import org.geneontology.obographs.model.meta.AbstractPropertyValue.Builder; +import java.util.List; /** * A {@link PropertyValue} that represents a textual definition of an ontology class or * property - * - * @author cjm * + * @author cjm */ -public class DefinitionPropertyValue extends AbstractPropertyValue implements PropertyValue { - +@JsonDeserialize(builder = DefinitionPropertyValue.Builder.class) +public class DefinitionPropertyValue extends AbstractPropertyValue { + private DefinitionPropertyValue(Builder builder) { super(builder); } @@ -24,13 +25,15 @@ public static class Builder extends AbstractPropertyValue.Builder { public Builder val(String val) { return (Builder) super.val(val); } + public Builder xrefs(List xrefs) { return (Builder) super.xrefs(xrefs); } - + + @JsonCreator public DefinitionPropertyValue build() { return new DefinitionPropertyValue(this); } } - + } diff --git a/src/main/java/org/geneontology/obographs/model/meta/SynonymPropertyValue.java b/src/main/java/org/geneontology/obographs/model/meta/SynonymPropertyValue.java index a88cf59..53ed9f5 100644 --- a/src/main/java/org/geneontology/obographs/model/meta/SynonymPropertyValue.java +++ b/src/main/java/org/geneontology/obographs/model/meta/SynonymPropertyValue.java @@ -1,23 +1,23 @@ package org.geneontology.obographs.model.meta; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; +import org.geneontology.obographs.model.Meta; + import java.util.ArrayList; import java.util.Collections; import java.util.List; -import org.geneontology.obographs.model.Meta; -import org.geneontology.obographs.model.meta.DefinitionPropertyValue.Builder; - -import com.fasterxml.jackson.annotation.JsonIgnore; - /** * A {@link PropertyValue} that represents a an alternative term for a node - * - * @author cjm * + * @author cjm */ - -public class SynonymPropertyValue extends AbstractPropertyValue implements PropertyValue { +@JsonDeserialize(builder = SynonymPropertyValue.Builder.class) +public class SynonymPropertyValue extends AbstractPropertyValue { private final String synonymType; @@ -30,32 +30,29 @@ public String getSynonymType() { /** * OBO-style synonym scopes - * - * @author cjm * + * @author cjm */ public enum SCOPES { EXACT, NARROW, BROAD, RELATED - }; - + } + /** * properties from oboInOwl vocabulary that represent scopes - * - * @author cjm * + * @author cjm */ public enum PREDS { hasExactSynonym, hasNarrowSynonym, hasBroadSynonym, hasRelatedSynonym - }; + } private SynonymPropertyValue(Builder builder) { - super(builder); synonymType = builder.synonymType; } @@ -76,9 +73,9 @@ public List getTypes() { return new ArrayList<>(); } - public static class Builder extends AbstractPropertyValue.Builder { + @JsonProperty private String synonymType; @Override @@ -100,24 +97,22 @@ public Builder addType(String type) { public Builder scope(SCOPES scope) { PREDS pred = PREDS.hasRelatedSynonym; switch (scope) { - case EXACT: pred = PREDS.hasExactSynonym; break; - case RELATED: pred = PREDS.hasRelatedSynonym; break; - case BROAD: pred = PREDS.hasBroadSynonym; break; - case NARROW: pred = PREDS.hasNarrowSynonym; break; - + case EXACT: pred = PREDS.hasExactSynonym; break; + case RELATED: pred = PREDS.hasRelatedSynonym; break; + case BROAD: pred = PREDS.hasBroadSynonym; break; + case NARROW: pred = PREDS.hasNarrowSynonym; break; } super.pred(pred.toString()); return this; - } public Builder synonymType(String synonymType) { if (synonymType != null) this.synonymType = synonymType; return this; - } + @JsonCreator public SynonymPropertyValue build() { return new SynonymPropertyValue(this); } diff --git a/src/main/java/org/geneontology/obographs/model/meta/XrefPropertyValue.java b/src/main/java/org/geneontology/obographs/model/meta/XrefPropertyValue.java index f057018..470f9b0 100644 --- a/src/main/java/org/geneontology/obographs/model/meta/XrefPropertyValue.java +++ b/src/main/java/org/geneontology/obographs/model/meta/XrefPropertyValue.java @@ -1,11 +1,14 @@ package org.geneontology.obographs.model.meta; -import java.util.List; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonProperty; +import com.fasterxml.jackson.databind.annotation.JsonDeserialize; -import org.geneontology.obographs.model.meta.DefinitionPropertyValue.Builder; +import java.util.List; -public class XrefPropertyValue extends AbstractPropertyValue implements PropertyValue { +@JsonDeserialize(builder = XrefPropertyValue.Builder.class) +public class XrefPropertyValue extends AbstractPropertyValue { private final String lbl; @@ -27,12 +30,14 @@ public String getLbl() { public static class Builder extends AbstractPropertyValue.Builder { + @JsonProperty private String lbl; @Override public Builder val(String val) { return (Builder) super.val(val); } + public Builder lbl(String lbl) { this.lbl= lbl; return this; @@ -43,6 +48,7 @@ public Builder xrefs(List xrefs) { return (Builder) super.xrefs(xrefs); } + @JsonCreator public XrefPropertyValue build() { return new XrefPropertyValue(this); } diff --git a/src/test/java/org/geneontology/obographs/io/OgJsonGeneratorTest.java b/src/test/java/org/geneontology/obographs/io/OgJsonGeneratorTest.java index 6f7ba39..139829e 100644 --- a/src/test/java/org/geneontology/obographs/io/OgJsonGeneratorTest.java +++ b/src/test/java/org/geneontology/obographs/io/OgJsonGeneratorTest.java @@ -1,17 +1,18 @@ package org.geneontology.obographs.io; -import static org.junit.Assert.*; +import org.apache.commons.io.FileUtils; +import org.geneontology.obographs.model.*; +import org.geneontology.obographs.model.meta.SynonymPropertyValue; +import org.geneontology.obographs.model.meta.XrefPropertyValue; +import org.junit.Test; import java.io.File; import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; -import org.apache.commons.io.FileUtils; -import org.geneontology.obographs.model.Graph; -import org.geneontology.obographs.model.GraphDocument; -import org.geneontology.obographs.model.GraphDocumentTest; -import org.junit.Test; - -import com.fasterxml.jackson.core.JsonProcessingException; +import static org.junit.Assert.assertEquals; public class OgJsonGeneratorTest { @@ -23,6 +24,47 @@ public void test() throws IOException { FileUtils.writeStringToFile(new File("target/simple-example.json"), s); } - + @Test + public void testRead() throws IOException { + GraphDocument testGraphDocument = GraphDocumentTest.build(); + + Path tempFile = Files.createTempFile("simple-example", ".json"); + FileUtils.writeStringToFile(tempFile.toFile(), OgJsonGenerator.render(testGraphDocument)); + + GraphDocument graphDocument = OgJsonReader.readFile(tempFile.toFile()); + assertEquals(1, graphDocument.getGraphs().size()); + Graph graph = graphDocument.getGraphs().get(0); + assertEquals(2, graph.getNodes().size()); + + Node node1 = graph.getNodes().get(0); + assertEquals("GO:0005634", node1.getId()); + assertEquals("nucleus", node1.getLabel()); + Meta node1Meta = node1.getMeta(); + assertEquals("A membrane-bounded organelle of eukaryotic cells in which chromosomes are housed and " + + "replicated. In most cells, the nucleus contains all of the cell's chromosomes except the organellar " + + "chromosomes, and is the site of RNA synthesis and processing. In some species, or in specialized cell" + + " types, RNA metabolism or DNA replication may be absent.", node1Meta.getDefinition().getVal()); + assertEquals(Arrays.asList("GOC:go_curators"), node1Meta.getDefinition().getXrefs()); + assertEquals(Arrays.asList("goslim_yeast", "goslim_plant"), node1Meta.getSubsets()); + + XrefPropertyValue xrefPropertyValue = node1Meta.getXrefs().get(0); + assertEquals("ICD10:111", xrefPropertyValue.getVal()); + assertEquals("foo disease", xrefPropertyValue.getLbl()); + + SynonymPropertyValue synonymPropertyValue = node1Meta.getSynonyms().get(0); + assertEquals("cell nucleus", synonymPropertyValue.getVal()); + assertEquals("hasExactSynonym", synonymPropertyValue.getPred()); + assertEquals(Arrays.asList("GOC:go_curators"), synonymPropertyValue.getXrefs()); + + Node node2 = graph.getNodes().get(1); + assertEquals("GO:0005623", node2.getId()); + assertEquals("cell", node2.getLabel()); + + assertEquals(1, graph.getEdges().size()); + Edge edge = graph.getEdges().get(0); + assertEquals("GO:0005634", edge.getSub()); + assertEquals("part_of", edge.getPred()); + assertEquals("GO:0005623", edge.getObj()); + } }