gonum.org/v1/gonum@v0.14.0/graph/formats/rdf/urna_example_test.go (about) 1 // Copyright ©2020 The Gonum Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 package rdf_test 6 7 import ( 8 "fmt" 9 "log" 10 "strings" 11 12 "gonum.org/v1/gonum/graph/formats/rdf" 13 ) 14 15 func ExampleURDNA2015() { 16 for _, statements := range []string{ 17 ` 18 _:a <ex:q> <ex:p> . 19 _:b <ex:q> <ex:p> . 20 _:c <ex:p> _:a . 21 _:d <ex:p> _:b . 22 _:c <ex:r> _:d . 23 `, 24 ` 25 _:c1 <ex:p> _:a1 . 26 _:b1 <ex:q> <ex:p> . 27 _:d1 <ex:p> _:b1 . 28 _:a1 <ex:q> <ex:p> . 29 _:c1 <ex:r> _:d1 . 30 `, 31 } { 32 // Decode the statement stream. 33 dec := rdf.NewDecoder(strings.NewReader(statements)) 34 var s []*rdf.Statement 35 for { 36 l, err := dec.Unmarshal() 37 if err != nil { 38 break 39 } 40 s = append(s, l) 41 } 42 43 relabeled, err := rdf.URDNA2015(nil, s) 44 if err != nil { 45 log.Fatal(err) 46 } 47 for _, s := range relabeled { 48 fmt.Println(s) 49 } 50 fmt.Println() 51 } 52 53 // Output: 54 // 55 // _:c14n0 <ex:p> _:c14n2 . 56 // _:c14n1 <ex:p> _:c14n3 . 57 // _:c14n1 <ex:r> _:c14n0 . 58 // _:c14n2 <ex:q> <ex:p> . 59 // _:c14n3 <ex:q> <ex:p> . 60 // 61 // _:c14n0 <ex:p> _:c14n2 . 62 // _:c14n1 <ex:p> _:c14n3 . 63 // _:c14n1 <ex:r> _:c14n0 . 64 // _:c14n2 <ex:q> <ex:p> . 65 // _:c14n3 <ex:q> <ex:p> . 66 } 67 68 func ExampleURGNA2012() { 69 for _, statements := range []string{ 70 ` 71 _:a <ex:q> <ex:p> . 72 _:b <ex:q> <ex:p> . 73 _:c <ex:p> _:a . 74 _:d <ex:p> _:b . 75 _:c <ex:r> _:d . 76 `, 77 ` 78 _:c1 <ex:p> _:a1 . 79 _:b1 <ex:q> <ex:p> . 80 _:d1 <ex:p> _:b1 . 81 _:a1 <ex:q> <ex:p> . 82 _:c1 <ex:r> _:d1 . 83 `, 84 } { 85 // Decode the statement stream. 86 dec := rdf.NewDecoder(strings.NewReader(statements)) 87 var s []*rdf.Statement 88 for { 89 l, err := dec.Unmarshal() 90 if err != nil { 91 break 92 } 93 s = append(s, l) 94 } 95 96 relabeled, err := rdf.URGNA2012(nil, s) 97 if err != nil { 98 log.Fatal(err) 99 } 100 for _, s := range relabeled { 101 fmt.Println(s) 102 } 103 fmt.Println() 104 } 105 106 // Output: 107 // 108 // _:c14n0 <ex:p> _:c14n3 . 109 // _:c14n0 <ex:r> _:c14n1 . 110 // _:c14n1 <ex:p> _:c14n2 . 111 // _:c14n2 <ex:q> <ex:p> . 112 // _:c14n3 <ex:q> <ex:p> . 113 // 114 // _:c14n0 <ex:p> _:c14n3 . 115 // _:c14n0 <ex:r> _:c14n1 . 116 // _:c14n1 <ex:p> _:c14n2 . 117 // _:c14n2 <ex:q> <ex:p> . 118 // _:c14n3 <ex:q> <ex:p> . 119 }