Commit a53ce083 authored by Thibault Ehrhart's avatar Thibault Ehrhart

AdelAnnotator: use new model and filename format

parent fdbbcedb
......@@ -37,21 +37,20 @@ public class AdelAnnotator {
Files.list(Paths.get(AdelAnnotator.DUMP_PATH + FileSystems.getDefault().getSeparator()))
.filter(file -> file.toFile().isDirectory()).forEach(langDir -> {
try {
Files.list(langDir).filter(file -> file.toFile().getName().endsWith(".ttl")).forEach(file -> {
Files.list(langDir).filter(file -> file.toFile().getName().endsWith(".news.ttl")).forEach(file -> {
final Model model = ModelFactory.createDefaultModel();
final Model finalModel = ModelFactory.createDefaultModel();
model.add(RDFDataMgr.loadModel(file.toString()));
// Add asrael namespace to the model if needed
if (model.getNsPrefixURI("asrael") == null) {
model.setNsPrefix("asrael", "http://asrael.eurecom.fr/asrael#");
}
// Add asrael namespace to the final model
finalModel.setNsPrefix("asrael", "http://asrael.eurecom.fr/asrael#");
// Calculate total rows
int totalRows = 0;
final String queryCount = String.format(
"PREFIX rnews: <http://iptc.org/std/rNews/2011-10-07#> " +
"PREFIX asrael: <http://asrael.eurecom.fr/asrael#> " +
"SELECT (COUNT(?s) AS ?nb) WHERE { ?s rnews:description ?desc . MINUS { ?s asrael:context ?context . } }"
"SELECT (COUNT(?s) AS ?nb) WHERE { ?s rnews:articleBody ?desc . MINUS { ?s asrael:context ?context . } }"
);
try (QueryExecution qexecCount = QueryExecutionFactory.create(queryCount, model)) {
ResultSet rs = qexecCount.execSelect();
......@@ -67,7 +66,7 @@ public class AdelAnnotator {
final String query = String.format(
"PREFIX rnews: <http://iptc.org/std/rNews/2011-10-07#> " +
"PREFIX asrael: <http://asrael.eurecom.fr/asrael#> " +
"SELECT ?s ?desc (LANG(?desc) AS ?lang) WHERE { ?s rnews:description ?desc . MINUS { ?s asrael:context ?context . } }"
"SELECT ?s ?desc (LANG(?desc) AS ?lang) WHERE { ?s rnews:articleBody ?desc . MINUS { ?s asrael:context ?context . } }"
);
try (QueryExecution qexec = QueryExecutionFactory.create(query, model)) {
ResultSet rs = qexec.execSelect();
......@@ -125,13 +124,13 @@ public class AdelAnnotator {
Resource contextSubj = (Resource) binding2.get("s");
// Add the annotations model generated by ADEL, to our current model with news articles
model.add(annotationsModel);
finalModel.add(annotationsModel);
// Update news article by adding a link to the annotations context
Statement updateStatement = ResourceFactory.createStatement(subj,
ResourceFactory.createProperty("http://asrael.eurecom.fr/asrael#", "context"),
contextSubj);
model.add(updateStatement);
finalModel.add(updateStatement);
}
}
}
......@@ -139,13 +138,14 @@ public class AdelAnnotator {
}
// Overwrite the original turtle file
final String filePath = FilenameUtils.getPath(file.toString()) + FilenameUtils.getBaseName(file.toString()) + "." + FilenameUtils.getExtension(file.toString());
final String baseName = FilenameUtils.getBaseName(file.toString());
final String filePath = FilenameUtils.getPath(file.toString()) + baseName.substring(0, baseName.lastIndexOf(".news")) + ".adel.ttl";
AdelAnnotator.LOGGER.info("Writing annotations to file {}", filePath);
Path outFile = Paths.get(filePath);
try (final OutputStream outRdf = Files.newOutputStream(outFile, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) {
RDFDataMgr.write(
outRdf,
model,
finalModel,
RDFFormat.TURTLE_PRETTY
);
} catch (final IOException e) {
......
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