Slightly more informative closing message
[scpubgit/stemmatology.git] / analysis / idp_server / readData.idp
CommitLineData
51650966 1/** Create structure with stemma data, read from dot string **/
2procedure readStemma(stemmastring) {
3 local stemma = newstructure(V,"stemma")
4 local pipe = assert(io.popen("echo '"..stemmastring.."' | dot -Tplain"))
5 local s = pipe:read("*all")
6 pipe:close()
7-- Add nodes to the stemma.
8 local t = {}
9 for node in string.gmatch(s,"node%s(%S+)%s") do
10 table.insert(t,node)
11 end
12 stemma[V::Manuscript.type] = t
13-- Add edges to the stemma.
14 for n1,n2 in string.gmatch(s,"edge%s(%S+)%s(%S+)%s") do
15 maketrue(stemma[V::CopiedBy],{n1,n2})
16 end
17-- There are no more edges than the ones given.
18 stemma[V::CopiedBy].cf = stemma[V::CopiedBy].pf
19 return stemma
20}
21
22/** Create table of structures with sample data **/
23procedure readSamples(stemma,sampletable) {
24 local samples = {}
25 for i,groupings in ipairs(sampletable) do
26 local sample = newstructure(V,"sample"..tostring(i))
27 sample[V::Manuscript.type] = stemma[V::Manuscript.type]
28 sample[V::CopiedBy] = stemma[V::CopiedBy]
29 sample[V::Variant.type] = range(1,#groupings)
30 -- Add known equivalence relations to the sample.
31 for variant,grouping in ipairs(groupings) do
32 for _,element in ipairs(grouping) do
33 maketrue(sample[V::VariantOf].graph,{element,variant})
34 end
35 end
36 table.insert(samples,sample)
37 end
38 return samples
39}
40
41/** Show stemma using dot **/
42procedure showStemma(stemmastring) {
43 local f = assert(io.open("data/test.dot","w"))
44 f:write(stemmastring)
45 f:close()
46 os.execute("dotty data/test.dot &")
47}
48