[TASK] Allow toggling whether to shorten uris using prefixs.
This commit is contained in:
@@ -0,0 +1,45 @@
|
||||
package lu.jpt.csparqlproject.util;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* This is a small helper class which will be used on some occasions
|
||||
* to make output easier to read by providing a method to replace known
|
||||
* uris in (tuple) strings with their known prefix.
|
||||
*/
|
||||
public class PrefixManager {
|
||||
|
||||
/**
|
||||
* Key is the uri, value is its prefix
|
||||
*/
|
||||
private Map<String, String> prefixTable;
|
||||
|
||||
|
||||
public PrefixManager() {
|
||||
this.prefixTable = new HashMap<String, String>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Register a known prefix with its corresponding uri
|
||||
* @param prefix
|
||||
* @param uri
|
||||
*/
|
||||
public void registerPrefix(String prefix, String uri) {
|
||||
this.prefixTable.put(uri, prefix);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace all uris within a tuple with their know prefix
|
||||
* This is not efficient, but that is not the point
|
||||
* @param tuple as a string
|
||||
* @return shortened tuple string
|
||||
*/
|
||||
public String applyPrefix(String tuple) {
|
||||
for (Map.Entry<String, String> entry : this.prefixTable.entrySet()) {
|
||||
tuple = tuple.replace(entry.getKey(), entry.getValue() + ":");
|
||||
}
|
||||
return tuple;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user