-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.go
151 lines (109 loc) · 3.78 KB
/
main.go
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
rdf2smw is a commandline tool to convert from RDF data to MediaWiki XML Dump
files, for import using MediaWiki's built in importDump.php script.
Usage
./rdf2smw -in <infile> -out <outfile>
Flags
-in Input file in RDF N-triples format
-out Output file in (MediaWiki) XML format
Example usage
./rdf2smw -in mydata.nt -out mydata.xml
For importing the generated XML Dumps into MediaWiki, see this page:
https://www.mediawiki.org/wiki/Manual:Importing_XML_dumps
*/
package main
import (
"flag"
"fmt"
"github.com/rdfio/rdf2smw/components"
"os"
str "strings"
"github.com/flowbase/flowbase"
)
const (
BUFSIZE = 16
)
func main() {
//flowbase.InitLogDebug()
inFileName := flag.String("in", "", "The input file name")
outFileName := flag.String("out", "", "The output file name")
flag.Parse()
doExit := false
if *inFileName == "" {
fmt.Println("No filename specified to --in")
doExit = true
} else if *outFileName == "" {
fmt.Println("No filename specified to --out")
doExit = true
}
if doExit {
os.Exit(1)
}
// ------------------------------------------
// Initialize processes
// ------------------------------------------
// Create a pipeline runner
net := flowbase.NewNet()
// Read in-file
ttlFileRead := components.NewOsTurtleFileReader()
net.AddProcess(ttlFileRead)
// TripleAggregator
aggregator := components.NewTripleAggregator()
net.AddProcess(aggregator)
// Create an subject-indexed "index" of all triples
indexCreator := components.NewResourceIndexCreator()
net.AddProcess(indexCreator)
// Fan-out the triple index to the converter and serializer
indexFanOut := components.NewResourceIndexFanOut()
net.AddProcess(indexFanOut)
// Serialize the index back to individual subject-tripleaggregates
indexToAggr := components.NewResourceIndexToTripleAggregates()
net.AddProcess(indexToAggr)
// Convert TripleAggregate to WikiPage
triplesToWikiConverter := components.NewTripleAggregateToWikiPageConverter()
net.AddProcess(triplesToWikiConverter)
//categoryFilterer := components.NewCategoryFilterer([]string{"DataEntry"})
//net.AddProcess(categoryFilterer)
// Pretty-print wiki page data
//wikiPagePrinter := components.NewWikiPagePrinter()
//net.AddProcess(wikiPagePrinter)
useTemplates := true
xmlCreator := components.NewMWXMLCreator(useTemplates)
net.AddProcess(xmlCreator)
//printer := components.NewStringPrinter()
//net.AddProcess(printer)
templateWriter := components.NewStringFileWriter(str.Replace(*outFileName, ".xml", "_templates.xml", 1))
net.AddProcess(templateWriter)
propertyWriter := components.NewStringFileWriter(str.Replace(*outFileName, ".xml", "_properties.xml", 1))
net.AddProcess(propertyWriter)
pageWriter := components.NewStringFileWriter(*outFileName)
net.AddProcess(pageWriter)
snk := flowbase.NewSink()
net.AddProcess(snk)
// ------------------------------------------
// Connect network
// ------------------------------------------
ttlFileRead.OutTriple = aggregator.In
aggregator.Out = indexCreator.In
indexCreator.Out = indexFanOut.In
indexFanOut.Out["serialize"] = indexToAggr.In
indexFanOut.Out["conv"] = triplesToWikiConverter.InIndex
indexToAggr.Out = triplesToWikiConverter.InAggregate
//triplesToWikiConverter.OutPage = categoryFilterer.In
//categoryFilterer.Out = xmlCreator.InWikiPage
triplesToWikiConverter.OutPage = xmlCreator.InWikiPage
xmlCreator.OutTemplates = templateWriter.In
xmlCreator.OutProperties = propertyWriter.In
xmlCreator.OutPages = pageWriter.In
snk.Connect(templateWriter.OutDone)
snk.Connect(propertyWriter.OutDone)
snk.Connect(pageWriter.OutDone)
// ------------------------------------------
// Send in-data and run
// ------------------------------------------
go func() {
defer close(ttlFileRead.InFileName)
ttlFileRead.InFileName <- *inFileName
}()
net.Run()
}