Skip to content

Commit

Permalink
#513 Move Triplifier Register to model module
Browse files Browse the repository at this point in the history
  • Loading branch information
luigi-asprino committed Dec 4, 2024
1 parent e4ba29d commit 0ef3ecb
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 29 deletions.
23 changes: 15 additions & 8 deletions EXTENSION_MECHANISMS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Extension Mechanisms

You can extend SPARQL Anything by including new triplifiers.
To this end, you have into include the `engine` module within your dependencies.
You can extend SPARQL Anything by including custom triplifiers, functions or magic properties.
There are two ways of doing that: [wrapping the extension into a new package](#wrapping-the-extension-into-a-new-package) or [develop a plugin](#develop-a-plugin).

## Wrapping the extension into a new package

To wrap the extension into a new package, you have into include the `engine` module within your dependencies.

```
<dependency>
Expand All @@ -13,10 +17,10 @@ To this end, you have into include the `engine` module within your dependencies.

A maven project showing how to extend SPARQL Anything is available [here](https://github.com/SPARQL-Anything/JavaExtensionExample).

This project includes defines a new triplifier, called MyTriplifier, which reads the input resource byte-by-byte, transforms each byte into a character, and adds the character as a slot of the root container.
MyTriplifier is used to transform resources having mime type `my-mime-type` and extension `myext`.
This project defines a new triplifier, called `MyTriplifier`, which reads the input resource byte-by-byte, transforms each byte into a character, and adds the character as a slot of the root container.
`MyTriplifier` is used to transform resources having mime type `my-mime-type` and extension `myext`.

Source code of the MyTriplifier
Source code of the `MyTriplifier` class

```java
package sparqlanything.user;
Expand Down Expand Up @@ -78,7 +82,7 @@ public class MyTriplifier implements Triplifier {

Then, you can register the new triplifier via the following line.

```
```java
FacadeX.Registry.registerTriplifier(MyTriplifier.class.getCanonicalName(), new String[]{"myext"}, new String[]{"my-mime-type"});
```

Expand All @@ -88,7 +92,7 @@ Finally, you can use the Triplifier [as usual](README.md#usage). For example, vi
package sparqlanything.user ;

import io.github.sparqlanything.engine.FacadeX;
import io.github.sparqlanything.engine.TriplifierRegisterException;
import io.github.sparqlanything.model.TriplifierRegisterException;
import org.apache.jena.query.*;
import org.apache.jena.sparql.engine.main.QC;

Expand Down Expand Up @@ -134,4 +138,7 @@ which prints
| 2 | "b" |
| 3 | "c" |
--------------------
```
```

### Develop a plugin

2 changes: 1 addition & 1 deletion docs/EXTENSION_MECHANISMS.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ Finally, you can use the Triplifier [as usual](README.md#usage). For example, vi
package sparqlanything.user ;

import io.github.sparqlanything.engine.FacadeX;
import io.github.sparqlanything.engine.TriplifierRegisterException;
import io.github.sparqlanything.model.TriplifierRegisterException;
import org.apache.jena.query.*;
import org.apache.jena.sparql.engine.main.QC;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import freemarker.template.TemplateException;
import freemarker.template.TemplateExceptionHandler;
import io.github.sparqlanything.engine.FacadeX;
import io.github.sparqlanything.engine.TriplifierRegister;
import io.github.sparqlanything.model.TriplifierRegister;
import io.github.sparqlanything.model.annotations.Format;
import io.github.sparqlanything.model.annotations.Triplifier;
import org.apache.jena.query.ARQ;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,16 @@

package io.github.sparqlanything.documentationgenerator;

import io.github.sparqlanything.engine.TriplifierRegister;
import io.github.sparqlanything.model.TriplifierRegister;
import io.github.sparqlanything.model.IRIArgument;
import io.github.sparqlanything.model.annotations.Example;
import io.github.sparqlanything.model.annotations.Examples;
import io.github.sparqlanything.model.annotations.Format;
import io.github.sparqlanything.model.annotations.Option;
import org.apache.commons.io.IOUtils;
import org.apache.commons.text.diff.StringsComparator;
import org.apache.jena.query.*;

import java.io.IOException;
import java.lang.reflect.Field;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.*;

public class FormatSection {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.github.sparqlanything.engine;

import io.github.sparqlanything.model.TriplifierRegister;
import org.apache.jena.sparql.algebra.Op;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.sparql.engine.ExecutionContext;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.github.sparqlanything.facadeiri.FacadeIRIParser;
import io.github.sparqlanything.model.IRIArgument;
import io.github.sparqlanything.model.Triplifier;
import io.github.sparqlanything.model.TriplifierRegister;
import org.apache.jena.sparql.algebra.Algebra;
import org.apache.jena.sparql.algebra.Op;
import org.apache.jena.sparql.algebra.op.OpService;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
import io.github.sparqlanything.engine.functions.*;
import io.github.sparqlanything.engine.functions.reflection.ReflectionFunctionFactory;
import io.github.sparqlanything.model.Triplifier;
import io.github.sparqlanything.model.TriplifierRegister;
import io.github.sparqlanything.model.TriplifierRegisterException;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.text.WordUtils;
import org.apache.commons.text.similarity.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import io.github.sparqlanything.model.SPARQLAnythingConstants;
import io.github.sparqlanything.model.TriplifierHTTPException;
import io.github.sparqlanything.model.TriplifierRegister;
import org.apache.jena.graph.Triple;
import org.apache.jena.query.ARQ;
import org.apache.jena.sparql.algebra.Op;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import io.github.sparqlanything.engine.functions.IsFacadeXExtension;
import io.github.sparqlanything.model.IRIArgument;
import io.github.sparqlanything.model.Triplifier;
import io.github.sparqlanything.model.TriplifierRegister;
import io.github.sparqlanything.zip.FolderTriplifier;
import org.apache.commons.io.FilenameUtils;
import org.apache.jena.graph.Triple;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package io.github.sparqlanything.engine.test;

import io.github.sparqlanything.engine.FacadeX;
import io.github.sparqlanything.engine.TriplifierRegister;
import io.github.sparqlanything.model.TriplifierRegister;
import org.apache.jena.query.*;
import org.apache.jena.sparql.engine.main.QC;
import org.junit.Assert;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package io.github.sparqlanything.engine.test;

import io.github.sparqlanything.engine.FacadeXOpExecutor;
import io.github.sparqlanything.engine.TriplifierRegister;
import io.github.sparqlanything.engine.TriplifierRegisterException;
import io.github.sparqlanything.model.TriplifierRegister;
import io.github.sparqlanything.model.TriplifierRegisterException;
import org.apache.commons.io.IOUtils;
import org.apache.jena.graph.Graph;
import org.apache.jena.graph.NodeFactory;
Expand All @@ -33,15 +33,12 @@
import org.apache.jena.query.ResultSet;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.sparql.ARQConstants;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.sparql.core.DatasetGraphFactory;
import org.apache.jena.sparql.engine.ExecutionContext;
import org.apache.jena.sparql.engine.main.OpExecutor;
import org.apache.jena.sparql.engine.main.OpExecutorFactory;
import org.apache.jena.sparql.engine.main.QC;
import org.apache.jena.sparql.graph.GraphFactory;
import org.apache.jena.sparql.service.ServiceExecutorRegistry;
import org.apache.jena.sys.JenaSystem;
import org.junit.Test;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public void testIssue280() throws URISyntaxException {
public void testIssue284_2() throws URISyntaxException {
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything", "Trace");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.model.HTTPHelper", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.engine.TriplifierRegister", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.model.TriplifierRegister", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.engine.FacadeX", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.facadeiri", "ERROR");

Expand Down Expand Up @@ -526,7 +526,7 @@ public void testIssue280_2() throws URISyntaxException {
public void testIssue284() throws URISyntaxException {
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything", "Trace");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.model.HTTPHelper", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.engine.TriplifierRegister", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.model.TriplifierRegister", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.engine.FacadeX", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.facadeiri", "ERROR");

Expand Down Expand Up @@ -578,7 +578,7 @@ public void testIssue284() throws URISyntaxException {
public void testIssue291() {
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything", "Trace");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.model.HTTPHelper", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.engine.TriplifierRegister", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.model.TriplifierRegister", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.engine.FacadeX", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.facadeiri", "ERROR");
Dataset ds = DatasetFactory.createGeneral();
Expand Down Expand Up @@ -631,7 +631,7 @@ public void testIssue291() {
public void testIssue295() throws URISyntaxException, IOException {
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything", "Trace");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.model.HTTPHelper", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.engine.TriplifierRegister", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.model.TriplifierRegister", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.engine.FacadeX", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.facadeiri", "ERROR");
Dataset ds = DatasetFactory.createGeneral();
Expand Down Expand Up @@ -698,7 +698,7 @@ public void testIssue334() throws URISyntaxException, IOException {
public void testIssue197() throws URISyntaxException, IOException {
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything", "Trace");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.model.HTTPHelper", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.engine.TriplifierRegister", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.model.TriplifierRegister", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.engine.FacadeX", "ERROR");
// System.setProperty("org.slf4j.simpleLogger.log.io.github.sparqlanything.facadeiri", "ERROR");
Dataset ds = DatasetFactory.createGeneral();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.github.sparqlanything.engine;
package io.github.sparqlanything.model;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

package io.github.sparqlanything.engine;
package io.github.sparqlanything.model;

public class TriplifierRegisterException extends Exception {

Expand Down

0 comments on commit 0ef3ecb

Please sign in to comment.