Skip to content

Commit

Permalink
Merge pull request #1619 from afs/rdf-patch
Browse files Browse the repository at this point in the history
GH-1618: RDF Patch
  • Loading branch information
afs authored Nov 22, 2022
2 parents 7f5da17 + d378e8c commit 85c5115
Show file tree
Hide file tree
Showing 139 changed files with 13,588 additions and 56 deletions.
6 changes: 6 additions & 0 deletions apache-jena-libs/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@

<dependencies>

<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-rdfpatch</artifactId>
<version>4.7.0-SNAPSHOT</version>
</dependency>

<dependency>
<groupId>org.apache.jena</groupId>
<artifactId>jena-shacl</artifactId>
Expand Down
18 changes: 18 additions & 0 deletions apache-jena/bat/rdfpatch.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
@echo off
@rem Licensed under the terms of http://www.apache.org/licenses/LICENSE-2.0

if "%JENAROOT%" == "" goto :rootNotSet
set JENA_HOME=%JENAROOT%
:rootNotSet

if NOT "%JENA_HOME%" == "" goto :okHome
echo JENA_HOME not set
exit /B

:okHome
set JENA_CP=%JENA_HOME%\lib\*;
set LOGGING=file:%JENA_HOME%/log4j2.properties

@rem JVM_ARGS comes from the environment.
java %JVM_ARGS% -Dlog4j.configurationFile="%LOGGING%" -cp "%JENA_CP%" rdfpatch.rdfpatch %*
exit /B
108 changes: 108 additions & 0 deletions apache-jena/bin/rdfpatch
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
#!/bin/sh
## Licensed under the terms of http://www.apache.org/licenses/LICENSE-2.0

resolveLink() {
local NAME=$1

if [ -L "$NAME" ]; then
case "$OSTYPE" in
darwin*|bsd*)
# BSD style readlink behaves differently to GNU readlink
# Have to manually follow links
while [ -L "$NAME" ]; do
NAME=$( cd $NAME && pwd -P ) ;
done
;;
*)
# Assuming standard GNU readlink with -f for
# canonicalize and follow
NAME=$(readlink -f "$NAME")
;;
esac
fi

echo "$NAME"
}

# If JENA_HOME is empty
if [ -z "$JENA_HOME" ]; then
SCRIPT="$0"
# Catch common issue: script has been symlinked
if [ -L "$SCRIPT" ]; then
SCRIPT=$(resolveLink "$0")
# If link is relative
case "$SCRIPT" in
/*)
# Already absolute
;;
*)
# Relative, make absolute
SCRIPT=$( dirname "$0" )/$SCRIPT
;;
esac
fi

# Work out root from script location
JENA_HOME="$( cd "$( dirname "$SCRIPT" )/.." && pwd )"
export JENA_HOME
fi

# If JENA_HOME is a symbolic link need to resolve
if [ -L "${JENA_HOME}" ]; then
JENA_HOME=$(resolveLink "$JENA_HOME")
# If link is relative
case "$JENA_HOME" in
/*)
# Already absolute
;;
*)
# Relative, make absolute
JENA_HOME=$(dirname "$JENA_HOME")
;;
esac
export JENA_HOME
fi

if [ -z "$JAVA" ]
then
if [ -z "$JAVA_HOME" ]
then
JAVA="$(which java)"
else
JAVA="$JAVA_HOME/bin/java"
fi
fi

if [ -z "$JAVA" ]
then
(
echo "Cannot find a Java JDK."
echo "Please set either set JAVA or JAVA_HOME and put java (>=Java 11) in your PATH."
) 1>&2
exit 1
fi


# ---- Setup
# JVM_ARGS : don't set here but it can be set in the environment.
# Expand JENA_HOME but literal *
JENA_CP="$JENA_HOME"'/lib/*'
LOGGING="${LOGGING:--Dlog4j.configurationFile=file:$JENA_HOME/log4j2.properties}"

# Platform specific fixup
# On CYGWIN convert path and end with a ';'
case "$(uname)" in
CYGWIN*) JENA_CP="$(cygpath -wp "$JENA_CP");";;
esac

# Respect TMPDIR or TMP (windows?) if present
# important for tdbloader spill
if [ -n "$TMPDIR" ]
then
JVM_ARGS="$JVM_ARGS -Djava.io.tmpdir=\"$TMPDIR\""
elif [ -n "$TMP" ]
then
JVM_ARGS="$JVM_ARGS -Djava.io.tmpdir=\"$TMP\""
fi

"$JAVA" $JVM_ARGS $LOGGING -cp "$JENA_CP" rdfpatch.rdfpatch "$@"
1 change: 1 addition & 0 deletions apache-jena/cmd-maker
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ riotcmd.utf8
riotcmd.rdfxml
shacl.shacl
shex.shex
rdfpatch.rdfpatch
tdb.tdbbackup
tdb.tdbdump
tdb.tdbloader
Expand Down
58 changes: 43 additions & 15 deletions jena-arq/Grammar/RDF-Thrift/BinaryRDF.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
// Encoding in Thrift of RDF terms and other items
// for Graph, Datasets, Result Set and Patches

// Versioning considerations?

namespace java org.apache.jena.riot.thrift.wire

// ==== RDF Term Definitions
Expand All @@ -42,7 +40,7 @@ struct RDF_BNode {
1: required string label
}

// Common abbreviations for datatypes and other URIs?
// Common abbreviated for datatypes and other URIs?
// union with additional values.

struct RDF_Literal {
Expand Down Expand Up @@ -77,7 +75,6 @@ union RDF_Term {
7: RDF_UNDEF undefined
8: RDF_REPEAT repeat
9: RDF_Triple tripleTerm # RDF-star

# Value forms of literals.
10: i64 valInteger
11: double valDouble
Expand Down Expand Up @@ -122,17 +119,48 @@ struct RDF_DataTuple {
1: list<RDF_Term> row
}

// // ==== RDF Patch
//
// # Includes
// # Prefix declaration
//
// enum RDF_Patch {
// ADD,
// ADD_NO_OP, // ADD recorded that had no effect
// DELETE,
// DELETE_NO_OP // DELETE recorded that had no effect
// }
// ==== RDF Patch

enum PatchTxn { TX, TC, TA , Segment }

struct Patch_Prefix_Add {
1: optional RDF_Term graphNode;
2: required string prefix;
3: required string iriStr;
}

struct Patch_Prefix_Del {
1: optional RDF_Term graphNode;
2: required string prefix;
}

struct Patch_Header {
1: required string name;
2: required RDF_Term value;
}

struct Patch_Data_Add {
1: required RDF_Term s;
2: required RDF_Term p;
3: required RDF_Term o;
4: optional RDF_Term g;
}

struct Patch_Data_Del {
1: required RDF_Term s;
2: required RDF_Term p;
3: required RDF_Term o;
4: optional RDF_Term g;
}

union RDF_Patch_Row {
1: Patch_Header header;
2: Patch_Data_Add dataAdd;
3: Patch_Data_Del dataDel;
4: Patch_Prefix_Add prefixAdd;
5: Patch_Prefix_Del prefixDel;
6: PatchTxn txn;
}

// Local Variables:
// tab-width: 2
Expand Down
8 changes: 8 additions & 0 deletions jena-arq/Grammar/RDF-Thrift/gen-thrift
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,11 @@ do
perl -i.bak -p -e 's/^\@SuppressWarnings.*$/\@SuppressWarnings("all")/' $f
rm -f $f.bak
done

## PatchTxn.java
F="$PKG/PatchTxn.java"
if [ -e "$F" ]
then
sed -e 's/public int getValue/@Override public int getValue/' < $F > F
mv F $F
fi
23 changes: 16 additions & 7 deletions jena-arq/src/main/java/org/apache/jena/riot/WebContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public class WebContent {
public static final ContentType ctResultsJSON = ContentType.create(contentTypeResultsJSON);

public static final String contentTypeJSON = "application/json";
public static final ContentType ctJSON = ContentType.create(contentTypeJSON);
public static final ContentType ctJSON = ContentType.create(contentTypeJSON);

// Unofficial
public static final String contentTypeResultsProtobuf = "application/sparql-results+protobuf" ;
Expand All @@ -134,25 +134,34 @@ public class WebContent {
public static final ContentType ctResultsThrift = ContentType.create(contentTypeResultsThrift) ;

public static final String contentTypeSPARQLQuery = "application/sparql-query";
public static final ContentType ctSPARQLQuery = ContentType.create(contentTypeSPARQLQuery);
public static final ContentType ctSPARQLQuery = ContentType.create(contentTypeSPARQLQuery);

public static final String contentTypeSPARQLUpdate = "application/sparql-update";
public static final ContentType ctSPARQLUpdate = ContentType.create(contentTypeSPARQLUpdate);
public static final ContentType ctSPARQLUpdate = ContentType.create(contentTypeSPARQLUpdate);

public static final String contentTypeHTMLForm = "application/x-www-form-urlencoded";
public static final ContentType ctHTMLForm = ContentType.create(contentTypeHTMLForm);
public static final ContentType ctHTMLForm = ContentType.create(contentTypeHTMLForm);

public static final String contentTypeHTML = "text/html";
public static final ContentType ctTextHTML = ContentType.create(contentTypeHTML);

public static final String contentTypeTextCSV = "text/csv";
public static final ContentType ctTextCSV = ContentType.create(contentTypeTextCSV);
public static final ContentType ctTextCSV = ContentType.create(contentTypeTextCSV);

public static final String contentTypeTextTSV = "text/tab-separated-values";
public static final ContentType ctTextTSV = ContentType.create(contentTypeTextTSV);
public static final ContentType ctTextTSV = ContentType.create(contentTypeTextTSV);

// Unofficial
public static final String contentTypeSSE = "text/sse";
public static final ContentType ctSSE = ContentType.create(contentTypeSSE);
public static final ContentType ctSSE = ContentType.create(contentTypeSSE);

// Unofficial
public static final String contentTypePatch = "application/rdf-patch";
public static final ContentType ctPatch = ContentType.create(contentTypePatch);

// Unofficial
public static final String contentTypePatchThrift = "application/rdf-patch+thrift";
public static final ContentType ctPatchThrift = ContentType.create(contentTypePatchThrift);

public static final String charsetUTF8 = "utf-8";
public static final String charsetASCII = "ascii";
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 85c5115

Please sign in to comment.