예제 #1
0
func TestJSONTerm2Term(t *testing.T) {
	term := jsonld.NewResource("http://test.org/")
	res1 := jterm2term(term)
	res2 := NewResource("http://test.org/")
	assert.True(t, res2.Equal(res1))

	term = jsonld.NewLiteralWithDatatype("text", jsonld.NewResource("http://www.w3.org/2001/XMLSchema#hexBinary"))
	res1 = jterm2term(term)
	res2 = NewLiteralWithDatatype("text", NewResource("http://www.w3.org/2001/XMLSchema#hexBinary"))
	assert.True(t, res2.Equal(res1))
}
예제 #2
0
파일: jsonld.go 프로젝트: dennwc/cayley
func toTerm(qv quad.Value) gojsonld.Term {
	if qv == nil {
		return nil
	}
	switch v := qv.(type) {
	case quad.IRI:
		return gojsonld.NewResource(string(v))
	case quad.BNode:
		return gojsonld.NewBlankNode(string(v))
	case quad.TypedString:
		return gojsonld.NewLiteralWithDatatype(
			string(v.Value),
			gojsonld.NewResource(string(v.Type)),
		)
	case quad.LangString:
		return gojsonld.NewLiteralWithLanguageAndDatatype(
			string(v.Value),
			string(v.Lang),
			gojsonld.NewResource(gojsonld.XSD_STRING),
		)
	case quad.String:
		return gojsonld.NewLiteralWithDatatype(
			string(v),
			gojsonld.NewResource(gojsonld.XSD_STRING),
		)
	}
	t, err := turtle.Parse(quad.StringOf(qv))
	if err != nil {
		return gojsonld.NewLiteralWithDatatype(
			string(quad.StringOf(qv)),
			gojsonld.NewResource(gojsonld.XSD_STRING),
		)
	}
	switch v := t.(type) {
	case turtle.IRI:
		return gojsonld.NewResource(string(v))
	case turtle.BlankNode:
		return gojsonld.NewBlankNode(string(v))
	case turtle.String:
		return gojsonld.NewLiteralWithDatatype(
			string(v),
			gojsonld.NewResource(gojsonld.XSD_STRING),
		)
	case turtle.LangString:
		return gojsonld.NewLiteralWithLanguageAndDatatype(
			string(v.Value),
			v.Lang,
			gojsonld.NewResource(gojsonld.XSD_STRING),
		)
	case turtle.TypedString:
		return gojsonld.NewLiteralWithDatatype(
			string(v.Value),
			gojsonld.NewResource(string(v.Type)),
		)
	default:
		return gojsonld.NewLiteralWithDatatype(quad.StringOf(qv), gojsonld.NewResource(gojsonld.XSD_STRING))
	}
}