Cleaning and TODOs
This commit is contained in:
parent
1768e593a8
commit
05a7ecdbb6
1 changed files with 12 additions and 11 deletions
|
|
@ -37,6 +37,9 @@ package graph
|
||||||
|
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
|
// TODO(kortschak) Consider providing MashalJSON and UnmarshalJSON
|
||||||
|
// instead of using struct tags.
|
||||||
|
|
||||||
// Our triple struct, used throughout.
|
// Our triple struct, used throughout.
|
||||||
type Triple struct {
|
type Triple struct {
|
||||||
Subject string `json:"subject"`
|
Subject string `json:"subject"`
|
||||||
|
|
@ -74,6 +77,9 @@ func (d Direction) String() string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(kortschak) Consider writing methods onto the concrete type
|
||||||
|
// instead of the pointer. This needs benchmarking to make the decision.
|
||||||
|
|
||||||
// Per-field accessor for triples
|
// Per-field accessor for triples
|
||||||
func (t *Triple) Get(d Direction) string {
|
func (t *Triple) Get(d Direction) string {
|
||||||
switch d {
|
switch d {
|
||||||
|
|
@ -100,20 +106,15 @@ func (t *Triple) String() string {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *Triple) IsValid() bool {
|
func (t *Triple) IsValid() bool {
|
||||||
if t.Subject == "" {
|
return t.Subject != "" && t.Predicate != "" && t.Object != ""
|
||||||
return false
|
|
||||||
}
|
|
||||||
if t.Predicate == "" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
if t.Object == "" {
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
return true
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO(kortschak) NTriple looks like a good candidate for conversion
|
||||||
|
// to MarshalText() (text []byte, err error) and then move parsing code
|
||||||
|
// from nquads to here to provide UnmarshalText(text []byte) error.
|
||||||
|
|
||||||
// Prints a triple in N-Triple format.
|
// Prints a triple in N-Triple format.
|
||||||
func (t *Triple) ToNTriple() string {
|
func (t *Triple) NTriple() string {
|
||||||
if t.Provenance == "" {
|
if t.Provenance == "" {
|
||||||
//TODO(barakmich): Proper escaping.
|
//TODO(barakmich): Proper escaping.
|
||||||
return fmt.Sprintf("%s %s %s .", t.Subject, t.Predicate, t.Object)
|
return fmt.Sprintf("%s %s %s .", t.Subject, t.Predicate, t.Object)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue