Commit af65b0e2 authored by Thibault Ehrhart's avatar Thibault Ehrhart

Reformat code using Google Java Style, use org.json instead of com.googlecode.json-simple

parent 45c618ac
......@@ -62,8 +62,8 @@
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
......
......@@ -2,7 +2,7 @@ package fr.eurecom.asrael.adelannotator;
public class Main {
public static void main(final String... args) {
new AdelAnnotator().run();
}
public static void main(final String... args) {
new AdelAnnotator().run();
}
}
......@@ -2,7 +2,7 @@ package fr.eurecom.asrael.bratannotator;
public class Main {
public static void main(final String... args) {
new BratAnnotator().run();
}
public static void main(final String... args) {
new BratAnnotator().run();
}
}
package fr.eurecom.asrael.bratannotator.datatypes;
import com.github.jsonldjava.core.RDFDataset;
import fr.eurecom.asrael.bratannotator.utils.UUIDGenerator;
import org.apache.jena.datatypes.RDFDatatype;
import org.apache.jena.datatypes.xsd.XSDDatatype;
import org.apache.jena.rdf.model.*;
import org.apache.jena.vocabulary.*;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.rdf.model.ResourceFactory;
import org.apache.jena.vocabulary.RDF;
import java.time.LocalDateTime;
import java.util.HashMap;
import java.util.Map;
public class Annotation {
private static final String BASE_URI = "http://asrael.eurecom.fr/annotation/";
private String body;
private String source;
private int startPosition;
private int endPosition;
private String canonicalURL;
private static final String BASE_URI = "http://asrael.eurecom.fr/annotation/";
private String body;
private String source;
private int startPosition;
private int endPosition;
private String canonicalURL;
public void setBody(String body) {
this.body = body;
}
public void setBody(String body) {
this.body = body;
}
public void setSource(String source) {
this.source = source;
}
public void setSource(String source) {
this.source = source;
}
public void setStartPosition(int startPosition) {
this.startPosition = startPosition;
}
public void setStartPosition(int startPosition) {
this.startPosition = startPosition;
}
public void setEndPosition(int endPosition) {
this.endPosition = endPosition;
}
public void setEndPosition(int endPosition) {
this.endPosition = endPosition;
}
/**
* Create the RDF model of the current annotation.
*
* @return A RDF model corresponding to an annotation
*/
public final Model getModel() {
final Model model = ModelFactory.createDefaultModel();
final Map<String, String> prefixes = new HashMap<>();
final LocalDateTime today = LocalDateTime.now();
/**
* Create the RDF model of the current annotation.
*
* @return A RDF model corresponding to an annotation
*/
public final Model getModel() {
final Model model = ModelFactory.createDefaultModel();
final Map<String, String> prefixes = new HashMap<>();
prefixes.put("rdf", RDF.getURI());
prefixes.put("xsd", "http://www.w3.org/2001/XMLSchema#");
prefixes.put("oa", "http://www.w3.org/ns/oa#");
prefixes.put("rdf", RDF.getURI());
prefixes.put("xsd", "http://www.w3.org/2001/XMLSchema#");
prefixes.put("oa", "http://www.w3.org/ns/oa#");
model.setNsPrefixes(prefixes);
model.setNsPrefixes(prefixes);
model.add(ResourceFactory.createResource(
model.add(
ResourceFactory.createResource(
Annotation.BASE_URI + UUIDGenerator.generateUUID(this.canonicalURL)),
RDF.type,
ResourceFactory.createResource("http://www.w3.org/ns/oa#Annotation")
);
RDF.type,
ResourceFactory.createResource("http://www.w3.org/ns/oa#Annotation"));
// Body
model.add(ResourceFactory.createResource(
Annotation.BASE_URI + UUIDGenerator.generateUUID(this.canonicalURL)),
ResourceFactory.createProperty("http://www.w3.org/ns/oa#bodyValue"),
ResourceFactory.createPlainLiteral(this.body)
);
// Body
model.add(
ResourceFactory.createResource(
Annotation.BASE_URI + UUIDGenerator.generateUUID(this.canonicalURL)),
ResourceFactory.createProperty("http://www.w3.org/ns/oa#bodyValue"),
ResourceFactory.createPlainLiteral(this.body));
// Target
Resource hasTarget = model.createResource();
// Target -> hasSource
hasTarget.addProperty(
ResourceFactory.createProperty("http://www.w3.org/ns/oa#hasSource"),
ResourceFactory.createResource(this.source)
);
// Target -> hasSelector
Resource hasSelector = model.createResource();
hasSelector.addProperty(
RDF.type,
ResourceFactory.createResource("http://www.w3.org/ns/oa#TextPositionSelector")
);
hasSelector.addProperty(
ResourceFactory.createProperty("http://www.w3.org/ns/oa#start"),
ResourceFactory.createTypedLiteral(String.valueOf(this.startPosition), XSDDatatype.XSDnonNegativeInteger)
);
hasSelector.addProperty(
ResourceFactory.createProperty("http://www.w3.org/ns/oa#end"),
ResourceFactory.createTypedLiteral(String.valueOf(this.endPosition), XSDDatatype.XSDnonNegativeInteger)
);
// Add hasSelector to target
hasTarget.addProperty(
ResourceFactory.createProperty("http://www.w3.org/ns/oa#hasSelector"),
hasSelector
);
// Add hasTarget to annotation
model.add(ResourceFactory.createResource(
Annotation.BASE_URI + UUIDGenerator.generateUUID(this.canonicalURL)),
ResourceFactory.createProperty("http://www.w3.org/ns/oa#hasTarget"),
hasTarget
);
// Target
Resource hasTarget = model.createResource();
// Target -> hasSource
hasTarget.addProperty(
ResourceFactory.createProperty("http://www.w3.org/ns/oa#hasSource"),
ResourceFactory.createResource(this.source));
// Target -> hasSelector
Resource hasSelector = model.createResource();
hasSelector.addProperty(
RDF.type, ResourceFactory.createResource("http://www.w3.org/ns/oa#TextPositionSelector"));
hasSelector.addProperty(
ResourceFactory.createProperty("http://www.w3.org/ns/oa#start"),
ResourceFactory.createTypedLiteral(
String.valueOf(this.startPosition), XSDDatatype.XSDnonNegativeInteger));
hasSelector.addProperty(
ResourceFactory.createProperty("http://www.w3.org/ns/oa#end"),
ResourceFactory.createTypedLiteral(
String.valueOf(this.endPosition), XSDDatatype.XSDnonNegativeInteger));
// Add hasSelector to target
hasTarget.addProperty(
ResourceFactory.createProperty("http://www.w3.org/ns/oa#hasSelector"), hasSelector);
// Add hasTarget to annotation
model.add(
ResourceFactory.createResource(
Annotation.BASE_URI + UUIDGenerator.generateUUID(this.canonicalURL)),
ResourceFactory.createProperty("http://www.w3.org/ns/oa#hasTarget"),
hasTarget);
return model;
}
return model;
}
public void setCanonicalURL(String canonicalURL) {
this.canonicalURL = canonicalURL;
}
public void setCanonicalURL(String canonicalURL) {
this.canonicalURL = canonicalURL;
}
}
......@@ -10,31 +10,29 @@ import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;
/**
* @author Julien Plu
*/
/** @author Julien Plu */
public final class UUIDGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(UUIDGenerator.class);
private static final Logger LOGGER = LoggerFactory.getLogger(UUIDGenerator.class);
private UUIDGenerator() {
}
/**
* Generate an UUID from a seed.
*
* @param seed The seed used to generate the UUID
* @return the generated UUID
*/
public static String generateUUID(final String seed) {
try {
final String hash = DatatypeConverter.printHexBinary(MessageDigest.getInstance(
"SHA-1").digest(seed.getBytes("UTF-8")));
private UUIDGenerator() {}
return UUID.nameUUIDFromBytes(hash.getBytes(Charset.forName("UTF-8"))).toString();
} catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) {
UUIDGenerator.LOGGER.error("Issue to detect a hash algorithm or with the encoding", ex);
}
/**
* Generate an UUID from a seed.
*
* @param seed The seed used to generate the UUID
* @return the generated UUID
*/
public static String generateUUID(final String seed) {
try {
final String hash =
DatatypeConverter.printHexBinary(
MessageDigest.getInstance("SHA-1").digest(seed.getBytes("UTF-8")));
return "";
return UUID.nameUUIDFromBytes(hash.getBytes(Charset.forName("UTF-8"))).toString();
} catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) {
UUIDGenerator.LOGGER.error("Issue to detect a hash algorithm or with the encoding", ex);
}
return "";
}
}
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.eurecom.asrael</groupId>
......@@ -38,8 +38,10 @@
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" />
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<transformer
implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>fr.eurecom.asrael.newscollector.Main</mainClass>
</transformer>
</transformers>
......@@ -82,8 +84,8 @@
<version>1.7.25</version>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
......
......@@ -4,7 +4,7 @@ import fr.eurecom.asrael.newscollector.agencefrancepresse.AgenceFrancePresse;
public final class Main {
public static void main(final String... args) {
new AgenceFrancePresse().run();
}
public static void main(final String... args) {
new AgenceFrancePresse().run();
}
}
......@@ -4,38 +4,35 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import javax.xml.bind.DatatypeConverter;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.UUID;
/**
* @author Julien Plu
*/
/** @author Julien Plu */
public final class UUIDGenerator {
private static final Logger LOGGER = LoggerFactory.getLogger(UUIDGenerator.class);
private UUIDGenerator() {
private static final Logger LOGGER = LoggerFactory.getLogger(UUIDGenerator.class);
private UUIDGenerator() {}
/**
* Generate an UUID from a seed.
*
* @param seed The seed used to generate the UUID
* @return the generated UUID
*/
public static String generateUUID(final String seed) {
try {
final String hash =
DatatypeConverter.printHexBinary(
MessageDigest.getInstance("SHA-1").digest(seed.getBytes("UTF-8")));
return UUID.nameUUIDFromBytes(hash.getBytes(Charset.forName("UTF-8"))).toString();
} catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) {
UUIDGenerator.LOGGER.error("Issue to detect a hash algorithm or with the encoding", ex);
}
/**
* Generate an UUID from a seed.
*
* @param seed The seed used to generate the UUID
* @return the generated UUID
*/
public static String generateUUID(final String seed) {
try {
final String hash = DatatypeConverter.printHexBinary(MessageDigest.getInstance(
"SHA-1").digest(seed.getBytes("UTF-8")));
return UUID.nameUUIDFromBytes(hash.getBytes(Charset.forName("UTF-8"))).toString();
} catch (NoSuchAlgorithmException | UnsupportedEncodingException ex) {
UUIDGenerator.LOGGER.error("Issue to detect a hash algorithm or with the encoding", ex);
}
return "";
}
return "";
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment