<commit_before>package se.kb.libris.whelks.component

import groovy.util.logging.Slf4j as Log

import org.openrdf.model.Resource
import org.openrdf.repository.Repository
import org.openrdf.repository.http.HTTPRepository
import org.openrdf.rio.RDFFormat


import se.kb.libris.whelks.*
import se.kb.libris.whelks.plugin.*

@Log
class SesameGraphStore extends BasicPlugin implements GraphStore {

    String sesameServer
    String repositoryID
    Repository repo
    String id = "sesameGraphStoreComponent"

    SesameGraphStore(String sesameServer, String repositoryID) {
        repo = new HTTPRepository(sesameServer, repositoryID)
        repo.initialize()
    }

    void update(URI graphUri, RDFDescription doc) {
        // TODO: not new conn for each? pool?
        def conn = repo.getConnection()
        try {
            log.debug("Store <${graphUri}> with content type '${doc.contentType}'")
            def bis = new ByteArrayInputStream(doc.data)
            def graphId = conn.valueFactory.createURI(graphUri.toString())
            conn.add(bis, graphUri.toString(), RDFFormat.TURTLE, [graphId] as Resource[])
        } catch (Exception e) {
            log.error("Error in document ${graphUri} - data:\n${new String(doc.data, 'utf-8')}\n\n")
            throw e
        } finally {
            conn.close()
        }
    }

    public void delete(URI graphUri, String whelkId) {
    }

    public SparqlResult sparql(String query) {
        return null
    }
}<commit_msg>Add note about clearing context in SesameGraphStore<commit_after>package se.kb.libris.whelks.component

import groovy.util.logging.Slf4j as Log

import org.openrdf.model.Resource
import org.openrdf.repository.Repository
import org.openrdf.repository.http.HTTPRepository
import org.openrdf.rio.RDFFormat


import se.kb.libris.whelks.*
import se.kb.libris.whelks.plugin.*

@Log
class SesameGraphStore extends BasicPlugin implements GraphStore {

    String sesameServer
    String repositoryID
    Repository repo
    String id = "sesameGraphStoreComponent"

    SesameGraphStore(String sesameServer, String repositoryID) {
        repo = new HTTPRepository(sesameServer, repositoryID)
        repo.initialize()
    }

    void update(URI graphUri, RDFDescription doc) {
        // TODO: not new conn for each? pool?
        def conn = repo.getConnection()
        try {
            log.debug("Store <${graphUri}> with content type '${doc.contentType}'")
            def bis = new ByteArrayInputStream(doc.data)
            def graphId = conn.valueFactory.createURI(graphUri.toString())
            //conn.clear(graphId) // TODO: should do this, but it is too slow by default
            conn.add(bis, graphUri.toString(), RDFFormat.TURTLE, graphId)
        } catch (Exception e) {
            log.error("Error in document ${graphUri} - data:\n${new String(doc.data, 'utf-8')}\n\n")
            throw e
        } finally {
            conn.close()
        }
    }

    public void delete(URI graphUri, String whelkId) {
    }

    public SparqlResult sparql(String query) {
        return null
    }
}
{'fraction_non_alphanumeric': 0.09944930353093619, 'fraction_numerical': 0.0012957563977972141, 'mean_word_length': 2.788957055214724, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4042896', 'n_tokens_mistral': 943, 'n_tokens_neox': 919, 'n_words': 224}