01: package org.ontoware.rdf2go.util.transform;
02:
03: import java.util.List;
04: import java.util.Map;
05:
06: import org.ontoware.rdf2go.model.Model;
07: import org.ontoware.rdf2go.model.node.URI;
08: import org.slf4j.Logger;
09: import org.slf4j.LoggerFactory;
10:
11: /**
12: * Transforms RDF syntactically according to configuration, e.g. renaming
13: * properties
14: *
15: * @author voelkel
16: *
17: */
18: public class Transformer {
19:
20: private static Logger log = LoggerFactory
21: .getLogger(Transformer.class);
22:
23: /**
24: * @param model
25: * @param rules -
26: * will be processed in order
27: */
28: public static void transform(Model model,
29: Map<String, URI> namespaceMap, List<TransformerRule> rules) {
30:
31: for (int i = 0; i < rules.size(); i++) {
32: log.debug("Executing rule " + i + " -------- "
33: + rules.get(i).getClass());
34: rules.get(i).applyRule(model, namespaceMap);
35: }
36:
37: }
38:
39: public static String toSparqlConstruct(
40: Map<String, URI> namespaceMap, String construct,
41: String where) {
42: StringBuffer query = new StringBuffer();
43: for (String ns : namespaceMap.keySet()) {
44: query.append("PREFIX ").append(ns).append(": ").append(
45: namespaceMap.get(ns).toSPARQL()).append("\n");
46: }
47: query.append("CONSTRUCT {\n");
48: query.append(construct).append("\n");
49: query.append("} WHERE {\n");
50: query.append(where).append("\n");
51: query.append("}\n");
52: log.debug("query \n" + query);
53: return query.toString();
54: }
55: }
|