コード例 #1
0
ファイル: value.go プロジェクト: dennwc/cayley
func (s Raw) Parse() (Value, error) {
	t, err := turtle.Parse(string(s))
	if err != nil {
		return nil, err
	}
	return FromTerm(t), nil
}
コード例 #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))
	}
}