<commit_before>package com.github.ansell.sesamerioextensions.rdfjson;

import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.HashSet;
import java.util.Set;

import org.openrdf.model.BNode;
import org.openrdf.model.Literal;
import org.openrdf.model.Model;
import org.openrdf.model.Resource;
import org.openrdf.model.URI;
import org.openrdf.model.Value;
import org.openrdf.model.ValueFactory;
import org.openrdf.rio.RDFHandler;
import org.openrdf.rio.RDFHandlerException;
import org.openrdf.rio.RDFParseException;
import org.openrdf.rio.WriterConfig;
import org.openrdf.rio.helpers.BasicWriterSettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;

/**
 * A utility class to help converting Sesame Graphs from and to RDF/JSON using Jackson.
 * 
 * @author <NAME> <EMAIL>
 */
public class RDFJSON
{
    private static final String STRING_NULL = "null";
    private static final String STRING_GRAPHS = "graphs";
    private static final String STRING_URI = "uri";
    private static final String STRING_BNODE = "bnode";
    private static final String STRING_DATATYPE = "datatype";
    private static final String STRING_LITERAL = "literal";
    private static final String STRING_LANG = "lang";
    private static final String STRING_TYPE = "type";
    private static final String STRING_VALUE = "value";
    
    private static final Logger log = LoggerFactory.getLogger(RDFJSON.class);
    
    private static final JsonFactory JSON_FACTORY = new JsonFactory();
    
    static
    {
        // Disable features that may work for most JSON where the field names are in limited supply,
        // but does not work for RDF/JSON where a wide range of URIs are used for subjects and
        // predicates
        RDFJSON.JSON_FACTORY.disable(JsonFactory.Feature.INTERN_FIELD_NAMES);
        RDFJSON.JSON_FACTORY.disable(JsonFactory.Feature.CANONICALIZE_FIELD_NAMES);
    }
    
    /**<commit_msg>setup jackson to prevent closing inputstream or outputstream<commit_after>package com.github.ansell.sesamerioextensions.rdfjson;

import java.io.IOException;
import java.io.Reader;
import java.io.Writer;
import java.util.HashSet;
import java.util.Set;

import org.openrdf.model.BNode;
import org.openrdf.model.Literal;
import org.openrdf.model.Model;
import org.openrdf.model.Resource;
import org.openrdf.model.URI;
import org.openrdf.model.Value;
import org.openrdf.model.ValueFactory;
import org.openrdf.rio.RDFHandler;
import org.openrdf.rio.RDFHandlerException;
import org.openrdf.rio.RDFParseException;
import org.openrdf.rio.WriterConfig;
import org.openrdf.rio.helpers.BasicWriterSettings;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.JsonFactory;
import com.fasterxml.jackson.core.JsonGenerationException;
import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonToken;

/**
 * A utility class to help converting Sesame Graphs from and to RDF/JSON using Jackson.
 * 
 * @author <NAME> <EMAIL>
 */
public class RDFJSON
{
    private static final String STRING_NULL = "null";
    private static final String STRING_GRAPHS = "graphs";
    private static final String STRING_URI = "uri";
    private static final String STRING_BNODE = "bnode";
    private static final String STRING_DATATYPE = "datatype";
    private static final String STRING_LITERAL = "literal";
    private static final String STRING_LANG = "lang";
    private static final String STRING_TYPE = "type";
    private static final String STRING_VALUE = "value";
    
    private static final Logger log = LoggerFactory.getLogger(RDFJSON.class);
    
    private static final JsonFactory JSON_FACTORY = new JsonFactory();
    
    static
    {
        // Disable features that may work for most JSON where the field names are in limited supply,
        // but does not work for RDF/JSON where a wide range of URIs are used for subjects and
        // predicates
        RDFJSON.JSON_FACTORY.disable(JsonFactory.Feature.INTERN_FIELD_NAMES);
        RDFJSON.JSON_FACTORY.disable(JsonFactory.Feature.CANONICALIZE_FIELD_NAMES);
        RDFJSON.JSON_FACTORY.disable(JsonGenerator.Feature.AUTO_CLOSE_TARGET);
    }
    
    /**
{'fraction_non_alphanumeric': 0.08681172291296625, 'fraction_numerical': 0.0008880994671403197, 'mean_word_length': 4.208092485549133, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 10}, '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': '7665910', 'n_tokens_mistral': 1405, 'n_tokens_neox': 1367, 'n_words': 356}