-
Notifications
You must be signed in to change notification settings - Fork 15
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
23 changed files
with
324 additions
and
1,328 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
This file was deleted.
Oops, something went wrong.
42 changes: 0 additions & 42 deletions
42
src/main/java/org/aksw/iguana/cc/config/elements/MetricConfig.java
This file was deleted.
Oops, something went wrong.
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
63 changes: 0 additions & 63 deletions
63
src/main/java/org/aksw/iguana/cc/lang/AbstractLanguageProcessor.java
This file was deleted.
Oops, something went wrong.
90 changes: 46 additions & 44 deletions
90
src/main/java/org/aksw/iguana/cc/lang/LanguageProcessor.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 |
---|---|---|
@@ -1,55 +1,57 @@ | ||
package org.aksw.iguana.cc.lang; | ||
|
||
import org.apache.http.Header; | ||
import org.apache.http.client.methods.CloseableHttpResponse; | ||
import org.apache.jena.rdf.model.Model; | ||
import org.json.simple.parser.ParseException; | ||
import org.xml.sax.SAXException; | ||
|
||
import javax.xml.parsers.ParserConfigurationException; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.time.Instant; | ||
import java.util.List; | ||
import java.util.concurrent.TimeoutException; | ||
import java.lang.annotation.ElementType; | ||
import java.lang.annotation.Retention; | ||
import java.lang.annotation.RetentionPolicy; | ||
import java.lang.annotation.Target; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.ServiceLoader; | ||
|
||
/** | ||
* Language Processor tells how to handle Http responses as well as how to analyze queries and generate stats. | ||
* Interface for abstract language processors that work on InputStreams. | ||
*/ | ||
public interface LanguageProcessor { | ||
|
||
/** | ||
* Returns the prefix used for the queries (e.g. sparql, query or document) | ||
* @return | ||
*/ | ||
String getQueryPrefix(); | ||
|
||
/** | ||
* Method to generate Triple Statistics for provided queries | ||
* | ||
* | ||
* @param taskID | ||
* @return Model with the triples to add to the results | ||
*/ | ||
Model generateTripleStats(List<QueryWrapper> queries, String resourcePrefix, String taskID); | ||
|
||
|
||
public abstract class LanguageProcessor { | ||
/** | ||
* Gets the result size of a given HTTP response | ||
* | ||
* @param response | ||
* @return | ||
* @throws ParserConfigurationException | ||
* @throws SAXException | ||
* @throws ParseException | ||
* @throws IOException | ||
* Provides the content type that a LanguageProcessor consumes. | ||
*/ | ||
Long getResultSize(CloseableHttpResponse response) throws ParserConfigurationException, SAXException, ParseException, IOException; | ||
|
||
Long getResultSize(Header contentTypeHeader, ByteArrayOutputStream content, long contentLength) throws ParserConfigurationException, SAXException, ParseException, IOException; | ||
|
||
@Retention(RetentionPolicy.RUNTIME) | ||
@Target(ElementType.TYPE) | ||
public @interface ContentType { | ||
String value(); | ||
} | ||
|
||
public interface LanguageProcessingData { | ||
Class<? extends LanguageProcessor> processor(); | ||
} | ||
|
||
public abstract LanguageProcessingData process(InputStream inputStream); | ||
|
||
final private static Map<String, Class<? extends LanguageProcessor>> processors = new HashMap<>(); | ||
|
||
static { | ||
for (LanguageProcessor processor : ServiceLoader.load(LanguageProcessor.class)) { | ||
LanguageProcessor.ContentType contentType = processor.getClass().getAnnotation(LanguageProcessor.ContentType.class); | ||
if (contentType != null) { | ||
processors.put(contentType.value(), processor.getClass()); | ||
} | ||
} | ||
} | ||
|
||
public static LanguageProcessor getInstance(String contentType) { | ||
Class<? extends LanguageProcessor> processorClass = processors.get(contentType); | ||
if (processorClass != null) { | ||
try { | ||
return processorClass.getDeclaredConstructor().newInstance(); | ||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException | | ||
NoSuchMethodException e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
throw new IllegalArgumentException("No LanguageProcessor for ContentType " + contentType); | ||
} | ||
|
||
long readResponse(InputStream inputStream, ByteArrayOutputStream responseBody) throws IOException, TimeoutException; | ||
|
||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.