func (store *MySQLStore) id2literal(id uint64) (term argo.Term) { cachedLit, ok := store.literalRevLookup[id] if !ok { row, ok := store.selectOne("SELECT value, language, datatype FROM %s_literals WHERE id = ?", id) if !ok || row == nil { return nil } cachedLit = &cachedLiteral{ Value: row[0].(string), Language: row[1].(string), DatatypeID: row[2].(uint64), } store.literalRevLookup[id] = cachedLit } var datatype argo.Term = nil if cachedLit.DatatypeID != 0 { datatypeURI := store.id2node(cachedLit.DatatypeID) datatype = argo.NewResource(datatypeURI) } return argo.NewLiteralWithLanguageAndDatatype(cachedLit.Value, cachedLit.Language, datatype) }
func parseLiteral(rp *ResultParser, itok xml.Token) (newState stateFunc, err error) { switch tok := itok.(type) { case xml.Comment: return parseLiteral, nil case xml.CharData: var datatype argo.Term if rp.literalDatatype != "" { datatype = argo.NewResource(rp.literalDatatype) } rp.currentResult[rp.currentBinding] = argo.NewLiteralWithLanguageAndDatatype(string(tok), rp.literalLanguage, datatype) rp.currentBinding = "" return parseLiteral, nil case xml.EndElement: // </literal> return parseBinding, nil } return nil, fmt.Errorf("Unexpected %T in parseLiteral", itok) }
func (f *Func) ToRDF(graph *argo.Graph) (term argo.Term) { term = str2term(f.URI) graph.AddTriple(term, argo.A, LOOP.Get("Function")) if len(f.Args) > 0 { argsTerm := argo.NewAnonNode() graph.AddTriple(term, LOOP.Get("args"), argsTerm) graph.AddTriple(argsTerm, argo.A, argo.RDF.Get("Bag")) argsList := graph.EncodeContainer(argsTerm) for _, arg := range f.Args { argsList <- arg.ToRDF(graph) } close(argsList) } var bodyList chan argo.Term for _, stmt := range f.Body { po, isPO := stmt.(*PredicateObjectPair) if isPO { var subject, object argo.Term if po.SubjVar == "" { subject = term } else { subject = str2term(po.SubjVar) } predicate := str2term(po.Predicate) res, isRes := po.Object.(ResourceObject) if isRes { object = str2term(string(res)) } else { lit := po.Object.(*LiteralObject) object = argo.NewLiteralWithLanguageAndDatatype(lit.Value, lit.Language, str2term(lit.Datatype)) } graph.AddTriple(subject, predicate, object) } else { expr := stmt.(Expression) if bodyList == nil { bodyTerm := argo.NewAnonNode() graph.AddTriple(term, LOOP.Get("code"), bodyTerm) bodyList = graph.EncodeList(bodyTerm) } bodyList <- expr.ToRDF(graph) } } if bodyList != nil { close(bodyList) } return term }