use of org.openrdf.model.Value in project vcell by virtualcell.
the class UniProtExtractor method extractBox.
public UniProtBox extractBox() {
UniProtBoxImp box = new UniProtBoxImp();
Iterator<Statement> stmtIter1 = model.match(null, UniProtConstants.replaces, null);
while (stmtIter1.hasNext()) {
Statement statement = stmtIter1.next();
Resource subject = statement.getSubject();
Value object = statement.getObject();
if (subject instanceof URI && object instanceof URI) {
String idSubject = id((URI) subject);
String idObject = id((URI) object);
if (StringUtil.notEmpty(idSubject) && StringUtil.notEmpty(idObject)) {
UniProtBox.Entry entrySubject = box.entry(idSubject);
UniProtBox.Entry entryObject = box.entry(idObject);
box.setReplaces(entrySubject, entryObject);
}
}
}
Iterator<Statement> stmtIter2 = model.match(null, UniProtConstants.replacedBy, null);
while (stmtIter2.hasNext()) {
Statement statement = stmtIter2.next();
Resource subject = statement.getSubject();
Value object = statement.getObject();
if (subject instanceof URI && object instanceof URI) {
String idSubject = id((URI) subject);
String idObject = id((URI) object);
if (StringUtil.notEmpty(idSubject) && StringUtil.notEmpty(idObject)) {
UniProtBox.Entry entrySubject = box.entry(idSubject);
UniProtBox.Entry entryObject = box.entry(idObject);
box.setReplaces(entryObject, entrySubject);
}
}
}
Iterator<Statement> stmtIter3 = model.match(null, UniProtConstants.recommendedName, null);
if (stmtIter3.hasNext()) {
while (stmtIter3.hasNext()) {
Statement statement = stmtIter3.next();
Resource entryNode = statement.getSubject();
Value nameNode = statement.getObject();
if (nameNode instanceof Resource) {
Resource nameResource = (Resource) nameNode;
Iterator<Statement> stmtIter4 = model.match(nameResource, UniProtConstants.fullName, null);
// System.out.println("hello world");
while (stmtIter4.hasNext()) {
Statement statement2 = stmtIter4.next();
Value objectNode = statement2.getObject();
// System.out.println("hello moon");
if (entryNode instanceof URI && objectNode instanceof Literal) {
String name = ((Literal) objectNode).stringValue();
UniProtBox.Entry entry = box.entry(UniProtConstants.idFromResource((URI) entryNode));
System.out.println("UniProtExtractor: name: " + name + "\tid: " + entry.id());
entry.setRecommendedName(name);
}
}
}
}
} else {
// sometimes, recommended name is not present for an uniprot id : check the full name
stmtIter3 = model.match(null, UniProtConstants.fullName, null);
while (stmtIter3.hasNext()) {
Statement statement2 = stmtIter3.next();
Resource entryNode = statement2.getSubject();
Value objectNode = statement2.getObject();
if (entryNode instanceof URI && objectNode instanceof Literal) {
String name = ((Literal) objectNode).stringValue();
UniProtBox.Entry entry = box.entry(UniProtConstants.idFromResource((URI) entryNode));
entry.setRecommendedName(name);
System.out.println("UniProtExtractor: name: " + name + "\tid: " + entry.id());
}
}
}
return box;
}
Aggregations