<commit_before>package net.qldarch.web.service;

import net.qldarch.web.model.QldarchOntology;
import net.qldarch.web.model.RdfDescription;
import net.qldarch.web.model.User;
import org.openrdf.model.Resource;
import org.openrdf.model.Value;
import org.openrdf.model.ValueFactory;
import org.openrdf.model.impl.URIImpl;
import org.openrdf.model.impl.ValueFactoryImpl;
import org.openrdf.query.*;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;

import static com.google.common.collect.Lists.newArrayList;
import static net.qldarch.web.service.KnownURIs.*;

public class RdfDataStoreDao {
    public static Logger logger = LoggerFactory.getLogger(SesameConnectionPool.class);

    private SesameConnectionPool connectionPool;
    private QldarchOntology ontology;

    public void insertRdfDescription(final RdfDescription rdf, final User user, final URI hasGraphPredicate, final URI graph) throws MetadataRepositoryException {
        this.getConnectionPool().performOperation(new RepositoryOperation() {
            public void perform(RepositoryConnection conn)
                    throws RepositoryException, MetadataRepositoryException {
                URIImpl userURI = new URIImpl(user.getUserURI().toString());
                URIImpl hasGraphURI = new URIImpl(hasGraphPredicate.toString());
                URIImpl contextURI = new URIImpl(graph.toString());
                URIImpl catalogURI = new URIImpl(QAC_CATALOG_GRAPH.toString());

                conn.add(userURI, hasGraphURI, contextURI, catalogURI);
                conn.add(rdf.asStatements(), contextURI);
            }
        });
    }

    public void deleteRdfResource(final URI resource) throws MetadataRepositoryException {
        this.getConnectionPool().performOperation(new RepositoryOperation() {
            public void perform(RepositoryConnection conn)
                    throws RepositoryException, MetadataRepositoryException {
                URIImpl resourceURI = new URIImpl(resource.toString());

                conn.remove(resourceURI, null, null);
                conn.remove((Resource)null, null, resourceURI);
            }
        });
    }

    public void deleteRdfStatement(final URI resource, final URI property, final String object, final URI objectType) throws MetadataRepositoryException {
        this.getConnectionPool().performOperation(new RepositoryOperation() {
            public void perform(RepositoryConnection conn)<commit_msg>Added PUT/DELETE functionality to  entities/expressions.<commit_after>package net.qldarch.web.service;

import net.qldarch.web.model.QldarchOntology;
import net.qldarch.web.model.RdfDescription;
import net.qldarch.web.model.User;
import org.openrdf.model.Resource;
import org.openrdf.model.Statement;
import org.openrdf.model.Value;
import org.openrdf.model.ValueFactory;
import org.openrdf.model.impl.URIImpl;
import org.openrdf.model.impl.ValueFactoryImpl;
import org.openrdf.query.*;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.List;

import static com.google.common.collect.Lists.newArrayList;
import static net.qldarch.web.service.KnownURIs.*;

public class RdfDataStoreDao {
    public static Logger logger = LoggerFactory.getLogger(SesameConnectionPool.class);

    private SesameConnectionPool connectionPool;
    private QldarchOntology ontology;

    public void insertRdfDescription(final RdfDescription rdf, final User user, final URI hasGraphPredicate, final URI graph) throws MetadataRepositoryException {
        this.getConnectionPool().performOperation(new RepositoryOperation() {
            public void perform(RepositoryConnection conn)
                    throws RepositoryException, MetadataRepositoryException {
                URIImpl userURI = new URIImpl(user.getUserURI().toString());
                URIImpl hasGraphURI = new URIImpl(hasGraphPredicate.toString());
                URIImpl contextURI = new URIImpl(graph.toString());
                URIImpl catalogURI = new URIImpl(QAC_CATALOG_GRAPH.toString());

                conn.add(userURI, hasGraphURI, contextURI, catalogURI);
                conn.add(rdf.asStatements(), contextURI);
            }
        });
    }

    public void updateRdfDescription(final RdfDescription rdf, final URI graph) throws MetadataRepositoryException {
        this.getConnectionPool().performOperation(new RepositoryOperation() {
            public void perform(RepositoryConnection conn)
                    throws RepositoryException, MetadataRepositoryException {
                URIImpl contextURI = new URIImpl(graph.toString());

                for (Statement s : rdf.asStatements()) {
                    conn.remove(s.getSubject(), s.getPredicate(), null, contextURI);
                    conn.add(s.getSubject(), s.getPredicate(), s.getObject(), contextURI);
                }
            }
        });
    }
    
    public void deleteRdfResource(final URI resource) throws MetadataRepositoryException {
        this.getConnectionPool().performOperation(new RepositoryOperation() {
            public void perform(RepositoryConnection conn)
                    throws RepositoryException, MetadataRepositoryException {
                URIImpl resourceURI = new URIImpl(resource.toString());

                conn.remove(resourceURI, null, null);
                conn.remove((Resource)null, null, resourceURI);
            }
        });
    }

    public void deleteRdfStatement(final URI resource, final URI property, final String object, final URI objectType) throws MetadataRepositoryException {
        this.getConnectionPool().performOperation(new RepositoryOperation() {
            public void perform(RepositoryConnection conn)
{'fraction_non_alphanumeric': 0.08471211118464593, 'fraction_numerical': 0.0006618133686300463, 'mean_word_length': 3.374095513748191, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '1561680', 'n_tokens_mistral': 1585, 'n_tokens_neox': 1559, 'n_words': 338}