I'm new to scala and spark and I need to build a graph from a dataframe. this is the structure of my dataframe where S and O are nodes and column P presents edges.
+---------------------------+---------------------+----------------------------+
|S |P |O |
+---------------------------+---------------------+----------------------------+
|http://website/Jimmy_Carter|http://web/name |James Earl Carter |
|http://website/Jimmy_Car |http://web/country |http://website/United_States|
|http://website/Jimmy_Car |http://web/birthPlace|http://web/Georgia_(US) |
+---------------------------+---------------------+----------------------------+
This is the code of the dataframe and I want to create a graph from the dataframe "dfA"
val test = sc
.textFile("testfile.ttl")
.map(_.split(" "))
.map(p => Triple(Try(p(0).toString()).toOption,
Try(p(1).toString()).toOption,
Try(p(2).toString()).toOption))
.toDF()
val url_regex = """^(?:"|<{1}\s?)(.*)(?:>(?:\s\.)?|,\s.*)$"""
val dfA = test
.withColumn("Subject", regexp_extract($"Subject", url_regex, 1))
.withColumn("Predicate", regexp_extract($"Predicate", url_regex, 1))
.withColumn("Object", regexp_extract($"Object", url_regex, 1))