Debian Codegraph @

examples/3-rdfloader/exampleRDFLoader.go

raw symbols SCIP
1 package main
2
3 import (
4 "fmt"
5 rdfloader "github.com/spdx/gordf/rdfloader"
6 "os"
7 )
8
9 func main() {
10 // expects user to enter the file name.
11 // sample run :
12 // go run exampleRDFLoader.go ../sample-docs/rdf/input.rdf
13
14 // checking if input arguments are ok.
15 if len(os.Args) != 2 {
16 fmt.Printf("Usage: %v <input.rdf>\n", os.Args[0])
17 fmt.Printf("\tTo parse the <input.rdf> file and\n")
18 fmt.Printf("\tPrint some of it's Triples\n")
19 os.Exit(1) // there was an error processing input.
20 }
21
22 filePath := os.Args[1]
23
24 rdfParser, err := rdfloader.LoadFromFilePath(filePath)
25 if err != nil {
26 fmt.Printf("error load rdf file: %v\n", err)
27 os.Exit(1)
28 }
29
30 // maximum number of triples to display.
31 maxNTriples := 10
32 i := 0
33 // parser.Triples is a dictionary of the form {triple-hash => triple}
34 for tripleHash := range rdfParser.Triples {
35 if i == maxNTriples {
36 break
37 }
38 i++
39 triple := rdfParser.Triples[tripleHash]
40 fmt.Printf("Triple %v:\n", i)
41 fmt.Println("\tSubject:", triple.Subject)
42 fmt.Println("\tPredicate:", triple.Predicate)
43 fmt.Println("\tObject:", triple.Object)
44 }
45 }