0
美好的一天大家, 我想創建一個字典從一個RDF文件使用Apache耶拿,創建模型後,我採取每個語句,並按主題,謂詞和對象分割文件,然後給每個唯一的URI分配一個數字,空白節點和文字,但是當我創建地圖時,出現關於地圖的錯誤有太多爭論,我不明白爲什麼,有人可以幫助我? 代碼如下:用SCALA地圖創建字典
var x:Int=0
val dictionary:scala.collection.immutable.Map[Node, Int]
// read the RDF/XML file
model.read(in, null)
val iter:StmtIterator = model.listStatements()
// print out the predicate, subject and object of each statement
def print {
while (iter.hasNext) {
{
x+=1
val stmt: Statement = iter.nextStatement
val subject: Node = stmt.getSubject.asNode()
dictionary(subject,x)
x+=1
val predicate: Node = stmt.getPredicate.asNode()
dictionary(predicate,x)
x+=1
val obj: Node = stmt.getObject.asNode()
dictionary(obj,x)
}
}
for ((k,v) <- dictionary) printf("key: %s, value: %s\n", k, v)
}