Tool can now print its intermediate state

このコミットが含まれているのは:
Cory Slep 2018-12-05 23:50:20 +01:00
コミット d2182dc3b9
2個のファイルの変更38行の追加2行の削除

ファイルの表示

@ -47,9 +47,9 @@ func main() {
if err != nil {
panic(err)
}
_, err = rdf.ParseVocabulary(registry, inputJSON)
p, err := rdf.ParseVocabulary(registry, inputJSON)
if err != nil {
panic(err)
}
fmt.Printf("done\n")
fmt.Printf("done\n%s\n", p)
}

ファイルの表示

@ -1,6 +1,7 @@
package rdf
import (
"bytes"
"fmt"
"net/url"
)
@ -18,6 +19,15 @@ type ParsedVocabulary struct {
References map[string]Vocabulary
}
func (p ParsedVocabulary) String() string {
var b bytes.Buffer
b.WriteString(fmt.Sprintf("Vocab:\n%s", p.Vocab))
for k, v := range p.References {
b.WriteString(fmt.Sprintf("Reference %s:\n\t%s\n", k, v))
}
return b.String()
}
// Vocabulary contains the type, property, and value definitions for a single
// ActivityStreams or extension vocabulary.
type Vocabulary struct {
@ -26,6 +36,20 @@ type Vocabulary struct {
Values map[string]VocabularyValue
}
func (v Vocabulary) String() string {
var b bytes.Buffer
for k, v := range v.Types {
b.WriteString(fmt.Sprintf("Type %s:\n\t%s\n", k, v))
}
for k, v := range v.Properties {
b.WriteString(fmt.Sprintf("Property %s:\n\t%s\n", k, v))
}
for k, v := range v.Values {
b.WriteString(fmt.Sprintf("Value %s:\n\t%s\n", k, v))
}
return b.String()
}
func (v *Vocabulary) SetType(name string, a *VocabularyType) error {
if v.Types == nil {
v.Types = make(map[string]VocabularyType, 1)
@ -67,6 +91,10 @@ type VocabularyValue struct {
Zero string
}
func (v VocabularyValue) String() string {
return fmt.Sprintf("Value=%s,%s,%s,%s", v.Name, v.URI, v.DefinitionType, v.Zero)
}
func (v *VocabularyValue) SetName(s string) {
v.Name = s
}
@ -99,6 +127,10 @@ type VocabularyType struct {
Examples []VocabularyExample
}
func (v VocabularyType) String() string {
return fmt.Sprintf("Type=%s,%s,%s", v.Name, v.URI, v.Notes)
}
func (v *VocabularyType) SetName(s string) {
v.Name = s
}
@ -144,6 +176,10 @@ type VocabularyProperty struct {
NaturalLanguageMap bool
}
func (v VocabularyProperty) String() string {
return fmt.Sprintf("Property=%s,%s,%s,%s,%s", v.Name, v.URI, v.Notes, v.Functional, v.NaturalLanguageMap)
}
func (v *VocabularyProperty) SetName(s string) {
v.Name = s
}