use of org.apache.jena.rdf.model.Statement in project legato by DOREMUS-ANR.
the class SupportMergedKeys method fileParsing.
private static HashMap<String, HashSet<String>> fileParsing(String file) throws IOException {
HashMap<String, HashSet<String>> instancesPerProperty = new HashMap<>();
Model model = ModelManager.loadModel(file);
StmtIterator iter = model.listStatements();
while (iter.hasNext()) {
Statement stmt = iter.nextStatement();
Resource subject = stmt.getSubject();
Property prop = stmt.getPredicate();
String instance = subject.toString();
String property = prop.toString();
allInstances.add(instance);
if (instancesPerProperty.containsKey(property)) {
instancesPerProperty.get(property).add(instance);
} else {
HashSet<String> instances = new HashSet<>();
instances.add(instance);
instancesPerProperty.put(property, instances);
}
}
return instancesPerProperty;
}
use of org.apache.jena.rdf.model.Statement in project legato by DOREMUS-ANR.
the class KeysClassifier method getCommonProperties.
public static List<Property> getCommonProperties(Model srcModel, Model tgtModel) {
/**
**
* Get All Predicates of the source model
***
*/
List<Property> propSRC = new ArrayList<Property>();
StmtIterator iterSRCModel = srcModel.listStatements();
while (iterSRCModel.hasNext()) {
Statement stmt = iterSRCModel.nextStatement();
Property prop = stmt.getPredicate();
if (!(propSRC.contains(prop))) {
propSRC.add(prop);
}
}
/**
**
* Get All Common Predicates for both models
***
*/
List<Property> commonProperties = new ArrayList<Property>();
StmtIterator iterTGTModel = tgtModel.listStatements();
while (iterTGTModel.hasNext()) {
Statement stmt = iterTGTModel.nextStatement();
Property prop = stmt.getPredicate();
if (!(commonProperties.contains(prop)) && (propSRC.contains(prop))) {
// If "prop" is a common property for both datasets
commonProperties.add(prop);
}
}
return commonProperties;
}
Aggregations