All Downloads are FREE. Search and download functionalities are using the official Maven repository.

function.event.json.rq Maven / Gradle / Ivy

Go to download

Corese is a Semantic Web Factory (triple store and SPARQL endpoint) implementing RDF, RDFS, SPARQL 1.1 Query and Update, Shacl. STTL. LDScript.

The newest version!
#
# Create RDF from JSON on the fly
#
prefix ex: 

@event
select * where {
    ?s ?p ?o
}

@init
function us:init(q) {
    us:json2rdf()
}


# parse JSON document and create RDF triples
function us:json2rdf() {
   let (js = xt:json(us:json())) {
        for (book in xt:get(js, "book")) {
            let (name = xt:get(book, "author"),
                title = xt:get(book, "title")) {
                    us:create(title, name)
            }
        }
    }
}

# create triples
function us:create(title, name) {
    query (insert { ?uri foaf:name ?name .  [ ex:author ?uri ; ex:title ?title] } 
    where { 
        bind (uri(concat(ex:, replace(name, " ", ""))) as ?uri)
        values (?title ?name) {(undef undef)}
    } )
}


# JSON document
function us:json() {
"""
{
"book" :
[
    {"title" : 1984,                        "author": "Georges Orwell"},
    {"title" : "Le Capital au XXIe siècle", "author": "Thomas Piketty"},
    {"title" : "Capital et idéologie",      "author": "Thomas Piketty"},
]
}    
"""
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy