| 1 |
package main |
| 2 |
|
| 3 |
import ( |
| 4 |
"fmt" |
| 5 |
"github.com/spdx/gordf/rdfloader/parser" |
| 6 |
xmlreader "github.com/spdx/gordf/rdfloader/xmlreader" |
| 7 |
"os" |
| 8 |
) |
| 9 |
|
| 10 |
func main() { |
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
if len(os.Args) != 2 { |
| 17 |
fmt.Printf("Usage: %v <input.rdf>\n", os.Args[0]) |
| 18 |
fmt.Printf("\tTo parse the <input.rdf> file and\n") |
| 19 |
fmt.Printf("\tPrint some of it's Triples\n") |
| 20 |
os.Exit(1) |
| 21 |
} |
| 22 |
|
| 23 |
filePath := os.Args[1] |
| 24 |
xmlReader, err := xmlreader.XMLReaderFromFilePath(filePath) |
| 25 |
if err != nil { |
| 26 |
|
| 27 |
fmt.Printf("error reading the rdf file %v: %v", filePath, err) |
| 28 |
os.Exit(1) |
| 29 |
} |
| 30 |
rootBlock, err := xmlReader.Read() |
| 31 |
if err != nil { |
| 32 |
|
| 33 |
fmt.Printf("error parsing the xml content of the rdf file") |
| 34 |
os.Exit(1) |
| 35 |
} |
| 36 |
rdfParser := parser.New() |
| 37 |
err = rdfParser.Parse(rootBlock) |
| 38 |
if err != nil { |
| 39 |
fmt.Printf("error parsing file: %v\n", err) |
| 40 |
os.Exit(1) |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
maxNTriples := 10 |
| 45 |
if len(rdfParser.Triples) < maxNTriples { |
| 46 |
|
| 47 |
maxNTriples = len(rdfParser.Triples) |
| 48 |
} |
| 49 |
|
| 50 |
i := 0 |
| 51 |
|
| 52 |
for tripleHash := range rdfParser.Triples { |
| 53 |
if i == maxNTriples { |
| 54 |
break |
| 55 |
} |
| 56 |
i++ |
| 57 |
triple := rdfParser.Triples[tripleHash] |
| 58 |
fmt.Printf("Triple %v:\n", i) |
| 59 |
fmt.Println("\tSubject:", triple.Subject) |
| 60 |
fmt.Println("\tPredicate:", triple.Predicate) |
| 61 |
fmt.Println("\tObject:", triple.Object) |
| 62 |
} |
| 63 |
} |