[英]Filtering vertices with properties GraphX
嗨,我试图通过它们的属性过滤这些三胞胎并打印它们,但是我遇到了麻烦。 图中一些三胞胎的示例是:
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
如果只想按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))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.