-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
388 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,3 +34,6 @@ results.tsv | |
.vscode | ||
dependency-reduced-pom.xml | ||
|
||
|
||
.travis.yml | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
layout: default | ||
title: Overview | ||
nav_order: 10 | ||
--- | ||
|
||
# LSQ Maven Plugin | ||
|
||
The [Linked SPARQL Queries](https://lsq.aksw.org/) (LSQ) Maven Plugin features the goals: | ||
|
||
* `rdfize`: Extracts SPARQL queries from Web server logs (e.g. Apache, Virtuoso) and emits quad-based RDF data. Each graph corresponds to one query. | ||
* `benchmark`: Takes a SPARQL query log as input and runs the queries against a configured endpoint. | ||
The query log may be supplied in various formats, including that of the output of `rdfize`. | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
lsq-maven-plugin/src/main/java/org/aksw/maven/plugin/lsq/DatasetOneNgImplBackport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package org.aksw.maven.plugin.lsq; | ||
|
||
import org.aksw.jenax.arq.dataset.api.DatasetOneNg; | ||
import org.aksw.jenax.arq.dataset.impl.DatasetGraphOneNgImpl; | ||
import org.aksw.jenax.arq.dataset.impl.DatasetOneNgImpl; | ||
import org.apache.jena.rdf.model.RDFNode; | ||
|
||
public class DatasetOneNgImplBackport { | ||
public static DatasetOneNg naturalDataset(RDFNode resource) { | ||
return new DatasetOneNgImpl(DatasetGraphOneNgImpl.create(resource.asNode(), resource.getModel().getGraph())); | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
lsq-maven-plugin/src/main/java/org/aksw/maven/plugin/lsq/FileUtilsBackport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
package org.aksw.maven.plugin.lsq; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.nio.file.AtomicMoveNotSupportedException; | ||
import java.nio.file.FileAlreadyExistsException; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.nio.file.StandardCopyOption; | ||
import java.nio.file.StandardOpenOption; | ||
import java.util.Objects; | ||
import java.util.function.Consumer; | ||
import java.util.function.Function; | ||
|
||
import org.aksw.commons.lambda.throwing.ThrowingConsumer; | ||
|
||
/** FIXME Delete this class as it has been moved to aksw-commons */ | ||
public class FileUtilsBackport { | ||
public static void moveAtomicIfSupported(Consumer<String> warnCallback, Path source, Path target) throws IOException { | ||
try { | ||
Files.move(source, target, StandardCopyOption.ATOMIC_MOVE, StandardCopyOption.REPLACE_EXISTING); | ||
} catch (AtomicMoveNotSupportedException e) { | ||
if (warnCallback != null) { | ||
warnCallback.accept(String.format("Atomic move from %s to %s failed, falling back to copy", source, target)); | ||
} | ||
Files.move(source, target, StandardCopyOption.REPLACE_EXISTING); | ||
} | ||
} | ||
|
||
/** Actions if the target already exists */ | ||
public static enum OverwriteMode { | ||
/** Raise an error */ | ||
ERROR, | ||
|
||
/** Overwrite the target */ | ||
OVERWRITE, | ||
|
||
/** Skip the write */ | ||
SKIP | ||
} | ||
|
||
public static void safeCreate(Path target, OverwriteMode overwriteAction, ThrowingConsumer<OutputStream> writer) throws Exception { | ||
safeCreate(target, null, overwriteAction, writer); | ||
} | ||
|
||
public static void safeCreate(Path target, Function<OutputStream, OutputStream> encoder, OverwriteMode overwriteAction, ThrowingConsumer<OutputStream> writer) throws Exception { | ||
Objects.requireNonNull(overwriteAction); | ||
|
||
String fileName = target.getFileName().toString(); | ||
String tmpFileName = "." + fileName + ".tmp"; // + new Random().nextInt(); | ||
Path tmpFile = target.resolveSibling(tmpFileName); | ||
|
||
Boolean fileExists = OverwriteMode.SKIP.equals(overwriteAction) || OverwriteMode.ERROR.equals(overwriteAction) | ||
? Files.exists(target) | ||
: null; | ||
|
||
// Check whether the target already exists before we start writing the tmpFile | ||
if (Boolean.TRUE.equals(fileExists) && OverwriteMode.ERROR.equals(overwriteAction)) { | ||
throw new FileAlreadyExistsException(target.toAbsolutePath().toString()); | ||
} | ||
|
||
if (!(Boolean.TRUE.equals(fileExists) && OverwriteMode.SKIP.equals(overwriteAction))) { | ||
Path parent = target.getParent(); | ||
if (parent != null) { | ||
Files.createDirectories(parent); | ||
} | ||
|
||
boolean allowOverwrite = OverwriteMode.OVERWRITE.equals(overwriteAction); | ||
// What to do if the tmp file already exists? | ||
try (OutputStream raw = Files.newOutputStream(tmpFile, allowOverwrite ? StandardOpenOption.CREATE : StandardOpenOption.CREATE_NEW); | ||
OutputStream out = encoder != null ? encoder.apply(raw) : raw) { | ||
writer.accept(out); | ||
out.flush(); | ||
} | ||
moveAtomicIfSupported(null, tmpFile, target); | ||
} | ||
} | ||
|
||
/** Delete a path if it is an empty directory */ | ||
public void deleteDirectoryIfEmpty(Path path) throws IOException { | ||
boolean isDirectory = Files.isDirectory(path); | ||
if (isDirectory) { | ||
boolean isEmpty = Files.list(path).count() == 0; | ||
if (isEmpty) { | ||
Files.delete(path); | ||
} | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.