//read the RDF/XML file
model.read(new InputStreamReader(
new FileInputStream(modelpath)), "");
//Predicate for filtering the linkToId
Selector selector = new SelectorImpl(null, RP.linkToId,
(RDFNode) null);
// Filtering
StmtIterator iter = model.listStatements(selector);
//sum for implied score
double sumImpliedScore = 0.00;
while (iter.hasNext()) {
//get the statement
Statement stmt = iter.nextStatement();
//get the resource
Resource node = stmt.getSubject();
//get the resource properties (linktoid and linktocategory)
String linktoid = node.getProperty(RP.linkToId)
.getObject().toString();
String linktocategory = node.getProperty(RP.linkToCategory)
.getObject().toString();
//construct the unique element (categname/documid)
String compare = linktocategory + SEPARATOR + linktoid;
//validate if the element was not already add it
if (listElemUnique.contains(compare)) {
listElemUnique.remove(compare);
//get the implied score
try {
sumImpliedScore = sumImpliedScore +
getImpliedScore(linktocategory, linktoid);
} catch (RpException e) {
logger.info("Exception in calculate the implied weight",
e);
}
}
}
//if there are still links-elements in the list and must to be add it to the model
if (!listElemUnique.isEmpty()) {
Iterator it = listElemUnique.iterator();
while (it.hasNext()) {
String elem = (String) it.next();
int index = elem.lastIndexOf(SEPARATOR);
String linktocategory = elem.substring(0, index);
String linktoid = elem.substring(index + 1);
//add the resource
Resource link = model.createResource()
.addProperty(RP.linkToCategory,
linktocategory).addProperty(RP.linkToId,
linktoid);
}
}
//update the calc_score of the node according to the average of the set
//Predicate for filtering the calc_score
Selector selScore = new SelectorImpl(null, RP.calcScore,
(RDFNode) null);
// Filtering
StmtIterator iterScore = model.listStatements(selScore);