Skip to content

Commit

Permalink
1.0 - Expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
filip26 committed May 24, 2020
1 parent 3924c4e commit 73913f2
Show file tree
Hide file tree
Showing 10 changed files with 47 additions and 44 deletions.
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# JSON-LD 1.1 Processor
# JSON-LD 1.1 Processor & API

An implementation of the [JSON-LD 1.1](https://www.w3.org/TR/json-ld/) specification in Java utilizing [JSONP](https://javaee.github.io/jsonp/) (Java API for JSON Processing).

Expand All @@ -24,13 +24,13 @@ The goal is to pass the [official test suite](https://github.com/w3c/json-ld-api

## Roadmap

- [x] 0.1 - Expansion
- [ ] 0.2 - Compaction
- [ ] 0.3 - Flattening
- [ ] 0.4 - RDF serialization
- [ ] 0.5 - RDF deserialization
- [ ] 0.6 - Framing
- [ ] 0.7 - API
- [x] 0.1 - [Expansion Algorithms](https://www.w3.org/TR/json-ld11-api/#expansion-algorithms)
- [ ] 0.2 - [Compaction Algorithms](https://www.w3.org/TR/json-ld11-api/#compaction-algorithms)
- [ ] 0.3 - [Flattening Algorithms](https://www.w3.org/TR/json-ld11-api/#flattening-algorithms)
- [ ] 0.4 - [RDF Algorithms](https://www.w3.org/TR/json-ld11-api/#rdf-serialization-deserialization-algorithms)
- [ ] 0.5 - [JSON-LD API](https://www.w3.org/TR/json-ld11-api/#the-application-programming-interface)
- [ ] 0.6 - Issues, code cleaning and optimization
- [ ] 0.7 - [Framing](https://www.w3.org/TR/json-ld11-framing/)
- [ ] 0.8 - Issues, code cleaning and optimization
- [ ] 1.0 - GA

Expand Down
15 changes: 8 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.apicatalog</groupId>
<artifactId>jsonp-ld</artifactId>
<version>0.1-SNAPSHOT</version>
<version>0.1</version>
<packaging>jar</packaging>

<name>JSONP-LD 1.1</name>

<description>
A JSON-LD 1.1 Processor
A JSON-LD 1.1 Processor &amp; API
</description>

<url>https://github.com/filip26/jsonp-ld</url>
Expand Down Expand Up @@ -116,11 +116,12 @@
</plugins>
</build>

<repositories>
<repository>
<id>github</id>
<name>GitHub filip26 Apache Maven Packages</name>
<url>https://maven.pkg.github.com/filip26/json-ld-api</url>
<repositories>
<!-- Test Resources -->
<repository>
<id>github</id>
<name>GitHub filip26 Apache Maven Packages</name>
<url>https://maven.pkg.github.com/filip26/json-ld-api</url>
</repository>
</repositories>

Expand Down
19 changes: 7 additions & 12 deletions src/main/java/com/apicatalog/jsonld/JsonLd11Processor.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ final class JsonLd11Processor implements JsonLdProcessor {

@Override
public JsonObject compact(JsonLdInput input) throws JsonLdError {
return compact(input, JsonLdOptions.DEFAULT);
return compact(input, new JsonLdOptions());
}

@Override
public JsonObject compact(JsonLdInput input, JsonLdContext context) throws JsonLdError {
return compact(input, context, JsonLdOptions.DEFAULT);
return compact(input, context, new JsonLdOptions());
}

@Override
Expand Down Expand Up @@ -57,20 +57,17 @@ public JsonArray expand(RemoteDocument input, final JsonLdOptions options) throw

@Override
public JsonObject flatten(JsonLdInput input) {
// TODO Auto-generated method stub
return null;
return flatten(input, null, new JsonLdOptions());
}

@Override
public JsonObject flatten(JsonLdInput input, JsonLdContext context) {
// TODO Auto-generated method stub
return null;
return flatten(input, context, new JsonLdOptions());
}

@Override
public JsonObject flatten(JsonLdInput input, JsonLdOptions options) {
// TODO Auto-generated method stub
return null;
return flatten(input, null, options);
}

@Override
Expand All @@ -81,8 +78,7 @@ public JsonObject flatten(JsonLdInput input, JsonLdContext context, JsonLdOption

@Override
public Collection<JsonObject> fromRdf(RdfDataset input) {
// TODO Auto-generated method stub
return Collections.emptyList();
return fromRdf(input, new JsonLdOptions());
}

@Override
Expand All @@ -93,8 +89,7 @@ public Collection<JsonObject> fromRdf(RdfDataset input, JsonLdOptions options) {

@Override
public RdfDataset toRdf(JsonLdInput input) {
// TODO Auto-generated method stub
return null;
return toRdf(input, new JsonLdOptions());
}

@Override
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/com/apicatalog/jsonld/api/JsonLdOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
*/
public final class JsonLdOptions {

public static final JsonLdOptions DEFAULT = new JsonLdOptions();

/**
* The base IRI to use when expanding or compacting the document.
* If set, this overrides the input document's IRI.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,7 @@ public ActiveContext build() throws JsonLdError {

String valueString = ((JsonString) value).getString();

//FIXME hack - ex: prefixes paas
if (valueString.indexOf(':', 1) != -1 || UriUtils.isURI(valueString) || valueString.isBlank() || CompactUri.isBlankNode(valueString)) {
if (UriUtils.isURI(valueString) || valueString.isBlank() || CompactUri.isBlankNode(valueString)) {

String vocabularyMapping =
result
Expand All @@ -404,8 +403,7 @@ public ActiveContext build() throws JsonLdError {
.documentRelative(true)
.build();

//FIXME hack - ex: prefixes paas
if (valueString.indexOf(':', 1) != -1 || UriUtils.isURI(vocabularyMapping) || CompactUri.isBlankNode(valueString)) {
if (UriUtils.isURI(vocabularyMapping) || CompactUri.isBlankNode(valueString)) {
result.vocabularyMapping = vocabularyMapping;

} else {
Expand Down
12 changes: 7 additions & 5 deletions src/main/java/com/apicatalog/jsonld/grammar/NodeObject.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ public class NodeObject {
}

public static final boolean isNodeObject(JsonValue value) {
return JsonUtils.isObject(value) && ((!value.asJsonObject().containsKey(Keywords.VALUE)
&& !value.asJsonObject().containsKey(Keywords.LIST) && !value.asJsonObject().containsKey(Keywords.SET))
|| (value.asJsonObject().size() == 2 && value.asJsonObject().containsKey(Keywords.GRAPH))
&& value.asJsonObject().containsKey(Keywords.CONTEXT))

return JsonUtils.isObject(value)
&& ((!value.asJsonObject().containsKey(Keywords.VALUE)
&& !value.asJsonObject().containsKey(Keywords.LIST)
&& !value.asJsonObject().containsKey(Keywords.SET))

|| (value.asJsonObject().size() == 2 && value.asJsonObject().containsKey(Keywords.GRAPH))
&& value.asJsonObject().containsKey(Keywords.CONTEXT))
;
// TODO https://www.w3.org/TR/json-ld11/#dfn-node-object
}
Expand Down
8 changes: 5 additions & 3 deletions src/main/java/com/apicatalog/jsonld/utils/JsonUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ public static final boolean contains(String text, JsonValue value) {
}

public static final boolean isScalar(final JsonValue value) {
return value != null && !ValueType.ARRAY.equals(value.getValueType())
&& !ValueType.OBJECT.equals(value.getValueType());
return value != null
&& !ValueType.ARRAY.equals(value.getValueType())
&& !ValueType.OBJECT.equals(value.getValueType());
}

public static final boolean isNotScalar(final JsonValue value) {
Expand Down Expand Up @@ -79,7 +80,8 @@ public static boolean isNumber(JsonValue value) {

public static boolean isNotBoolean(JsonValue value) {
return value == null
|| (!ValueType.TRUE.equals(value.getValueType()) && !ValueType.FALSE.equals(value.getValueType()));
|| (!ValueType.TRUE.equals(value.getValueType())
&& !ValueType.FALSE.equals(value.getValueType()));
}

public static boolean isTrue(JsonValue value) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/apicatalog/jsonld/utils/UriResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static String resolve(URI base, String relative) {

//FIXME hack
if (relative.endsWith(":")) {
relative = relative + ".";
relative += ".";
}

URI components = URI.create(relative);
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/apicatalog/jsonld/utils/UriUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@

import com.apicatalog.jsonld.grammar.Keywords;

public class UriUtils {
public final class UriUtils {

UriUtils() {
}

public static boolean isURI(String value) {


//FIXME hack
if (value.endsWith(":")) {
value += ".";
}

try {


// TODO ':' 1-length-1 indices only
return value != null && !value.isBlank()/* && value.indexOf(':', 1) != -1 */ && !Keywords.hasForm(value)
&& URI.create(value) != null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public static final JsonLdTestCaseOptions of(JsonObject o, String baseUri) {
if (o.containsKey("specVersion")) {
options.specVersion = Version.of(o.getString("specVersion"));
}

options.base = o.getString("base", null);
options.processingMode = o.getString("processingMode", null);

Expand Down

0 comments on commit 73913f2

Please sign in to comment.