您好我正在尝试按照其属性过滤这些三元组并打印它们但我遇到了麻烦。图中一些三元组的例子是:
SongProperty(Song,Dernière danse) --- GenericMusicProperties(Sung) ---> ArtistProperty(Artist,indila,-1)
SongProperty(Song,Watagatapitusberry) --- GenericMusicProperties(Sung) ---> ArtistProperty(Artist,pitbull,$45 Million)
SongProperty(Song,This Is How It Feels) --- GenericMusicProperties(WrittenBy) ---> WriterProperty(Writer,Clint Boon)
我正在尝试提取名为Watagatapitusberry的歌曲。
我正在尝试使用此过滤器:
val qry = allGraph.vertices.filter{
case (vp: SongProperty) => vp.songName == "Watagatapitusberry"
}
但我不确定它是否正确以及如何打印结果。
这些是用作顶点和边
的类class EdgeProperty extends Serializable
case class GenericMusicProperties(edgeType: String) extends EdgeProperty
case class WriterWriterProperties(weight: String, edgeType: String) extends EdgeProperty
case class ArtistWriterProperties(weight: String, edgeType: String) extends EdgeProperty
case class ArtistGenreProperties(weight: String, edgeType: String) extends EdgeProperty
class VertexProperty() extends Serializable
case class SongProperty(val vertexType: String, val songName: String) extends VertexProperty
case class BillboardProperty(val vertexType: String, val rank: Int, val year: Int) extends VertexProperty
case class ArtistProperty(val vertexType: String, val artistName: String, val netWorth: String) extends VertexProperty
case class WriterProperty(val vertexType: String, val writerName: String) extends VertexProperty
case class GenreProperty(val vertexType: String, val genreName: String) extends VertexProperty
case class GrammyProperty(val vertexType: String, val grammyNo: Int) extends VertexProperty
case class AliasProperty(val vertexType: String, val alias: String) extends VertexProperty
答案 0 :(得分:0)
如果你只想通过SongProperty过滤,通过songName和VertexProperty类型的其余元素留在集合中你应该这样做:
list.filter {
case s: SongProperty => s.songName == "Watagatapitusberry"
case _ => true
}
例如,输入:
val list = List(SongProperty("type1", "Strangers In the night"),
SongProperty("type1", "Watagatapitusberry"),
AliasProperty("type2", "alias1"),
GenreProperty("type1", "unknown"))
结果将是:
List(SongProperty(type1,Watagatapitusberry),
AliasProperty(type2,alias1),
GenreProperty(type1,unknown))