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

function.event.xml.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 XML on the fly
#
prefix ex: 

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

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


# parse XML document and create RDF triples
function us:xml2rdf() {
   let (xml = xt:xml(us:xml())) {
        for (book in xpath(xml, "/doc/book")) {            
            us:create(dom:getTextContent(xt:xpath(book, "title")), 
                dom:getTextContent(xt:xpath(book, "author")))
        }
    }
}

# 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)}
    } )
}


# XML document
function us:xml() {
"""

1984Georges Orwell
Le Capital au XXIe siècleThomas Piketty
Capital et idéologieThomas Piketty

    
"""
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy