Exemple #1
0
func (expr *FuncCall) ToRDF(graph *argo.Graph) (term argo.Term) {
	term = argo.NewAnonNode()

	graph.AddTriple(term, argo.A, str2term(expr.URI))

	for uri, arg := range expr.Args {
		graph.AddTriple(term, str2term(uri), arg.ToRDF(graph))
	}

	return term
}
Exemple #2
0
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
}