-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathSearch.scala
More file actions
52 lines (35 loc) · 1.21 KB
/
Search.scala
File metadata and controls
52 lines (35 loc) · 1.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import org.apache.spark._
import org.apache.spark.graphx.GraphLoader
import org.apache.spark.graphx._
import org.apache.spark.rdd.RDD
import scala.util.MurmurHash
import scala.util.Sorting
object Search {
def main(args: Array[String]) {
val typeOfReleations = graph.subgraph(epred = e => e.srcId == MurmurHash.stringHash(args(0)))
val sorted = typeOfReleations.triplets.collect.sortWith(_.attr.asInstanceOf[EdgeAttribute].x > _.attr.asInstanceOf[EdgeAttribute].x)
sorted.foreach(println(_))
for (tr <- sorted){
var typeOFRelation = ""
if (tr.attr.asInstanceOf[EdgeAttribute].y.equals(null)
|| tr.attr.asInstanceOf[EdgeAttribute].y == 0.0 )
{
typeOFRelation = "Type of relation is N/A"
}
else if (tr.attr.asInstanceOf[EdgeAttribute].y == 0)
{
typeOFRelation = "complementry"
}
else
{
typeOFRelation = "supplementry"
}
var message = "The product: '" + tr.srcAttr + "' is '"+ typeOFRelation +"' to product " + tr.dstAttr + " the relation strong by " + tr.attr.asInstanceOf[EdgeAttribute].x + " and secound wight "+ tr.attr.asInstanceOf[EdgeAttribute].y
println( message)
}
if(sorted.length ==0)
{
println("There is no related product to: " + args(0))
}
}
}