func (rewrite Rewrite) Apply(termPtr *argo.Term) { term := *termPtr termStr := "" switch realTerm := term.(type) { case *argo.Resource: termStr = realTerm.URI case *argo.BlankNode: termStr = "_:" + realTerm.ID case *argo.Literal: return } match := rewrite.Regexp.FindStringSubmatchIndex(termStr) if match != nil { resBytes := rewrite.Regexp.ExpandString(nil, rewrite.Template, termStr, match) resStr := string(resBytes) if len(resStr) >= 2 && resStr[0] == '_' && resStr[1] == ':' { *termPtr = argo.NewBlankNode(resStr[2:]) } else { *termPtr = argo.NewResource(resStr) } Rewritten++ } }
func node2term(node string) (term argo.Term) { if len(node) >= 2 && node[0] == '_' && node[1] == ':' { return argo.NewBlankNode(node[2:]) } else { return argo.NewResource(node) } return nil }
func parseBnode(rp *ResultParser, itok xml.Token) (newState stateFunc, err error) { switch tok := itok.(type) { case xml.Comment: return parseBnode, nil case xml.CharData: rp.currentResult[rp.currentBinding] = argo.NewBlankNode(string(tok)) rp.currentBinding = "" return parseBnode, nil case xml.EndElement: // </bnode> return parseBinding, nil } return nil, fmt.Errorf("Unexpected %T in parseBnode", itok) }
func str2term(uri string) (term argo.Term) { if len(uri) >= 2 && uri[0] == '_' && uri[1] == ':' { return argo.NewBlankNode(uri[2:]) } return argo.NewResource(uri) }