}
return true;
}
public boolean similarTopKAuthors(int transactionThreshhold, int k) {
Transaction tx = graphDB.beginTx();
try {
int transactionCount = 0;
for (Node author:graphDB.getAllNodes()){
if (!author.hasProperty("name"))continue;
HashMap<Node, Double> simAuthors = new HashMap<Node, Double>();
for (Relationship rel:author.getRelationships(DBRelationshipTypes.WRITTEN_BY)){
Node paper = rel.getOtherNode(author);
if (paper.hasProperty("title")){// i found a paper
for (Relationship simPaperRel:paper.getRelationships(DBRelationshipTypes.CO_CITATION_SCORE, Direction.OUTGOING)){
Node simPaper = simPaperRel.getEndNode();
if (simPaperRel.hasProperty(DBRelationshipProperties.CO_CITATION_SCORE)){
Double score = (Double)simPaperRel.getProperty(DBRelationshipProperties.CO_CITATION_SCORE);
for (Relationship authorRel:simPaper.getRelationships(DBRelationshipTypes.WRITTEN_BY)){
Node simAuthor = authorRel.getOtherNode(simPaper);
if (simAuthor.getId()==author.getId())continue;
if (simAuthors.containsKey(simAuthor))
simAuthors.put(simAuthor, simAuthors.get(simAuthor) + score);
else
simAuthors.put(simAuthor, score);
}
}
}
}
}
//get top k as usual and enter to data base:
Algo<Node, Double> a = new Algo<Node, Double>();
TreeMap<Double, Set<Node>> topkSimAuthors = a.getTopkElements(simAuthors, k);
int topkCnt=0;
for (Double score: topkSimAuthors.descendingKeySet()){
for (Node simAuthor: topkSimAuthors.get(score)){
Relationship simAuthorRel = author.createRelationshipTo(simAuthor, DBRelationshipTypes.SIM_AUTHOR);
simAuthorRel.setProperty(DBRelationshipProperties.SIM_AUTHOR_SCORE, score);
}
}
if (++transactionCount % transactionThreshhold == 0){
tx.success();
tx.finish();
tx = graphDB.beginTx();
IOHelper.log(transactionCount + " papers have been equiped with similarAuthor relations so far");
}
}
tx.success();
}finally{
tx.finish();
}
return true;
}