Browse Source

remove hardcoded paths

missing a file `examples/epicookbook/data/edges_from_code_1.jl`
pull/56/head
James Fairbanks 2 years ago
parent
commit
cd92b41b1f
  1. 1
      Project.toml
  2. 38
      bin/extract.jl
  3. 3
      src/SemanticModels.jl
  4. 12
      src/definitions.jl
  5. 15
      test/definitions.jl

1
Project.toml

@ -6,6 +6,7 @@ version = "0.1.0"
[deps]
CSV = "336ed68f-0bac-5ca0-87d4-7b16caf5d00b"
Cassette = "7057c7e9-c182-5462-911a-8362d720325c"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DataFramesMeta = "1313f7d8-7da2-5740-9ea0-a2ca25f37964"
DiffEqBase = "2b5f629d-d688-5b77-993f-72d75c75574e"

38
bin/extract.jl

@ -1,7 +1,4 @@
module Edges
include("../src/graph.jl")
include("../src/definitions.jl")
using DataFrames
using GraphDataFrameBridge
using MetaGraphs
@ -10,11 +7,17 @@ using LightGraphs
using Random
using DataFramesMeta
using Colors
using ParserCombinator
using GraphIO
export edgetype, edges, create_kg_from_code_edges, create_kg_from_markdown_edges, format_edges_dataframe, assign_vertex_colors_by_key, write_graph_to_dot_file
using SemanticModels.Graphs
using SemanticModels.Extraction
export edgetype,
edges,
create_kg_from_code_edges,
create_kg_from_markdown_edges,
format_edges_dataframe,
assign_vertex_colors_by_key,
write_graph_to_dot_file
function edgetype(var, val::Expr)
if val.head == :call
@ -129,9 +132,9 @@ function create_kg_from_code_edges(code_edges, G::MetaDiGraph)
return G_prime
end
function create_kg_from_markdown_edges()
function create_kg_from_markdown_edges(path)
G = Extraction.definitiongraph("../examples/epicookbook/epireceipes_Automates_GTRI_ASKE_2rules_output/json", Extraction.sequentialnamer())
G = Extraction.definitiongraph(path, Extraction.sequentialnamer())
# this is a hack for now..
# TODO: modify the markdown definitions.jl script to ensure vertex/edge props match the schema
@ -252,9 +255,9 @@ end
# julia -i --project ../bin/extract.jl ../examples/epicookbook/src/SEIRmodel.jl
using SemanticModels.Parsers
using SemanticModels.Graphs
using SemanticModels.Extraction
@debug "Done Loading Package"
include("../src/graph.jl")
include("../src/definitions.jl")
using DataFrames
using MetaGraphs
@ -286,16 +289,23 @@ for e in edg
println(e)
end
mdown_path = "../examples/epicookbook/epireceipes_Automates_GTRI_ASKE_2rules_output/json"
output_path = "../examples/epicookbook/data/edges_from_code_1.jl"
@info("Generating a knowledge graph from parsed Epicookbook markdown files.")
G_markdown = Edges.create_kg_from_markdown_edges()
G_markdown = MetaDiGraph()
try
G_markdown = Edges.create_kg_from_markdown_edges(mdown_path)
catch ex
@warn "Could not generate markdown edges" path=mdown_path ex=ex
end
G_code_and_markdown = Edges.create_kg_from_code_edges(output_path, G_markdown)
vcolors = Edges.assign_vertex_colors_by_key(G_code_and_markdown, :v_type)
dot_file_path = "../examples/epicookbook/data/dot_file_ex1.dot"
Edges.write_graph_to_dot_file(G_code_and_markdown, dot_file_path, "G_code_and_markdown", vcolors)
# TODO: this doesn't work because the dot file is not correctly formatted yet
#G_from_dot_file = loadgraph(dot_file_path, "G_code_and_markdown", DOTFormat())
#TODO: verify that the following cmd works
# run(`dot -Tsvg -O $dot_file_path`)

3
src/SemanticModels.jl

@ -8,7 +8,7 @@ module SemanticModels
using Unitful
using Unitful: Units
export Parsers
export Parsers, Extraction, Graphs
abstract type AbstractModel end
@ -110,6 +110,7 @@ function solve(m::CombinedModel)
end
include("graph.jl")
include("definitions.jl")
include("parse.jl")
end

12
src/definitions.jl

@ -121,17 +121,5 @@ function definitiongraph(files::Vector{String}, namefunc)
return metagraph
end
with_logger(ConsoleLogger(stderr, Logging.Debug)) do
def_output_dir = "../test/kg"
g = definitiongraph(def_output_dir, sequentialnamer())
@show g
#@show props(g)
for (k,v) in g.vprops
println(join(["Vertex", k, v], " "))
end
for (k,v) in g.eprops
println(join(["Edge", k, v], " "))
end
end
end

15
test/definitions.jl

@ -0,0 +1,15 @@
using Test
using SemanticModels.Extraction
with_logger(ConsoleLogger(stderr, Logging.Debug)) do
def_output_dir = "../test/kg"
g = definitiongraph(def_output_dir, sequentialnamer())
@show g
#@show props(g)
for (k,v) in g.vprops
println(join(["Vertex", k, v], " "))
end
for (k,v) in g.eprops
println(join(["Edge", k, v], " "))
end
end
Loading…
Cancel
Save