私はscalaとプログラミング全般にかなり慣れていません(楽しみのためだけです)。末尾再帰とコレクションを理解しようとしていますが、デバッグは本当に難しいです。
私は2つのリストを持っています:
val quoters = List[Map[String,List[String]]]
val quoted = List[Map[String,List[String]]]
元 :
val quoters = List(Map("author1"->List("1","7","8")),Map("author2"->List("2","4","6","3")),Map("author3"->List("5","2","1","3")))
val quoted = List(Map("author1"->List("5","6")),Map("author2"->List("5","8","1")),Map("author3"->List("4")))
"quoters" は "quoted" を引用し、"quoted" も "quoters" を引用します。
例では、次のとおりです。
author1 quoted author2 with "1" and "8",
author2 quoted author3 with "4",
author3 quoted author1 with "5" & author2 with "5" + "1"
「quoters」を引用する「quoted」を引用する「quoters」のサークルを見つけたい...
出力は次のようになります。
val quotesCircle = List(
Map("quoter"->"author1","receiver"->"author2","quote"->"4"),
Map("quoter"->"author2","receiver"->"author3","quote"->"2"),
Map("quoter"->"author3","receiver"->"author1","quote"->"1")
)
私の問題:
1/私はコレクションを誤用していると思います (Json のように思えます...)
2/リストのリストとの交差を取得できます:
def getintersect(q1:List[List[String]],q2:List[List[String]])={
for(x<-q1;r<-q2; if (x intersect r) != Nil)yield x intersect r
}
ただし、List of Maps の構造ではありません。
3/再帰のためにこれを試しましたが、機能していません...まあ、よくわかりません:
def getintersect(q1:List[List[String]],q2:List[List[String]])= {
def getQuotedFromIntersect(quoteMatching:List[String],quoted:List[List[String]]):List[List[String]]={
for(x<-q1;r<-q2; if (x intersect r) != Nil)
getQuotedFromIntersect(x intersect r,quoted)
}
}
私は十分に明確であることを願っています:/
前もって感謝します !
フェリックス