aboutsummaryrefslogtreecommitdiff
path: root/rdfloader/parser2v2/utils.go
diff options
context:
space:
mode:
Diffstat (limited to 'rdfloader/parser2v2/utils.go')
-rw-r--r--rdfloader/parser2v2/utils.go56
1 files changed, 40 insertions, 16 deletions
diff --git a/rdfloader/parser2v2/utils.go b/rdfloader/parser2v2/utils.go
index e0c3557..fd9ab77 100644
--- a/rdfloader/parser2v2/utils.go
+++ b/rdfloader/parser2v2/utils.go
@@ -1,8 +1,10 @@
package parser2v2
import (
+ "errors"
"fmt"
gordfParser "github.com/RishabhBhatnagar/gordf/rdfloader/parser"
+ "github.com/RishabhBhatnagar/gordf/rdfwriter"
urilib "github.com/RishabhBhatnagar/gordf/uri"
"github.com/spdx/tools-golang/spdx"
"regexp"
@@ -18,20 +20,6 @@ func getLastPartOfURI(uri string) string {
return parts[len(parts)-1]
}
-func stripLastPartOfUri(uri string) string {
- lastPart := getLastPartOfURI(uri)
- uri = strings.TrimSuffix(uri, lastPart)
- return uri
-}
-
-func stripJoiningChars(uri string) string {
- return strings.TrimSuffix(strings.TrimSuffix(uri, "/"), "#")
-}
-
-func isUriSame(uri1, uri2 string) bool {
- return stripJoiningChars(uri1) == stripJoiningChars(uri2)
-}
-
func (parser *rdfParser2_2) filterAllTriplesByString(subject, predicate, object string) (retTriples []*gordfParser.Triple) {
for _, triple := range parser.gordfParserObj.Triples {
if triple.Subject.ID == subject && triple.Predicate.ID == predicate && triple.Object.ID == object {
@@ -68,8 +56,44 @@ func isUriValid(uri string) bool {
return err == nil
}
+func (parser *rdfParser2_2) getNodeTypeFromTriples(triples []*gordfParser.Triple, node *gordfParser.Node) (string, error) {
+ if node == nil {
+ return "", errors.New("empty node passed to find node type")
+ }
+ typeTriples := rdfwriter.FilterTriples(triples, &node.ID, &RDF_TYPE, nil)
+ switch len(typeTriples) {
+ case 0:
+ return "", fmt.Errorf("node{%v} not associated with any type triple", node)
+ case 1:
+ return typeTriples[0].Object.ID, nil
+ default:
+ return "", fmt.Errorf("node{%v} is associated with more than one type triples", node)
+ }
+}
+
+func (parser *rdfParser2_2) getNodeType(node *gordfParser.Node) (string, error) {
+ return parser.getNodeTypeFromTriples(parser.gordfParserObj.Triples, node)
+}
-// Function Below this line is taken from the tvloader/parser2v2/utils.go
+func (parser *rdfParser2_2) nodeToTriples(node *gordfParser.Node) []*gordfParser.Triple {
+ if node == nil {
+ return []*gordfParser.Triple{}
+ }
+ return parser.nodeStringToTriples[node.String()]
+}
+
+func boolFromString(boolString string) (bool, error) {
+ switch strings.ToLower(boolString) {
+ case "true":
+ return true, nil
+ case "false":
+ return false, nil
+ default:
+ return false, fmt.Errorf("boolean string can be either true/false")
+ }
+}
+
+/* Function Below this line is taken from the tvloader/parser2v2/utils.go */
// used to extract DocumentRef and SPDXRef values from an SPDX Identifier
// which can point either to this document or to a different one
@@ -157,4 +181,4 @@ func ExtractSubs(value string, sep string) (string, string, error) {
subvalue := strings.TrimSpace(sp[1])
return subkey, subvalue, nil
-} \ No newline at end of file
+}