<commit_before>package org.deri.any23.writer;

import org.deri.any23.extractor.ExtractionContext;
import org.openrdf.model.Resource;
import org.openrdf.model.URI;
import org.openrdf.model.Value;
import org.openrdf.model.impl.ValueFactoryImpl;
import org.openrdf.rio.RDFHandlerException;
import org.openrdf.rio.RDFWriter;

class RDFWriterTripleHandler implements TripleHandler {
	private final RDFWriter writer;
	
	RDFWriterTripleHandler(RDFWriter destination) {
		writer = destination;
		try {
			writer.startRDF();
		} catch (RDFHandlerException e) {
			throw new RuntimeException(e);
		}
	}
	
	public void closeContext(ExtractionContext context) {
		// ignore
	}

	public void openContext(ExtractionContext context) {
		try {
			for (String prefix: context.getPrefixes().allPrefixes()) {
				writer.handleNamespace(prefix, 
						context.getPrefixes().getNamespaceURIFor(prefix));
			}
		} catch (RDFHandlerException ex) {
			throw new RuntimeException(ex);
		}
	}

	public void receiveTriple(Resource s, URI p, Value o, ExtractionContext context) {
		try {
			writer.handleStatement(
					ValueFactoryImpl.getInstance().createStatement(s, p, o));
		} catch (RDFHandlerException ex) {
			throw new RuntimeException(ex);
		}
	}
	
	public void receiveLabel(String label, ExtractionContext context) {
		// ignore metadata
	}

	public void close() {
		try {
			writer.endRDF();
		} catch (RDFHandlerException e) {
			throw new RuntimeException(e);
		}
	}
}<commit_msg>spo == null check in triple handler<commit_after>package org.deri.any23.writer;

import org.deri.any23.extractor.ExtractionContext;
import org.openrdf.model.Resource;
import org.openrdf.model.URI;
import org.openrdf.model.Value;
import org.openrdf.model.impl.ValueFactoryImpl;
import org.openrdf.rio.RDFHandlerException;
import org.openrdf.rio.RDFWriter;

class RDFWriterTripleHandler implements TripleHandler {
	private final RDFWriter writer;
	
	RDFWriterTripleHandler(RDFWriter destination) {
		writer = destination;
		try {
			writer.startRDF();
		} catch (RDFHandlerException e) {
			throw new RuntimeException(e);
		}
	}
	
	public void closeContext(ExtractionContext context) {
		// ignore
	}

	public void openContext(ExtractionContext context) {
		try {
			for (String prefix: context.getPrefixes().allPrefixes()) {
				writer.handleNamespace(prefix, 
						context.getPrefixes().getNamespaceURIFor(prefix));
			}
		} catch (RDFHandlerException ex) {
			throw new RuntimeException(ex);
		}
	}

	public void receiveTriple(Resource s, URI p, Value o, ExtractionContext context) {
		checkInput(s,p,o);
		
		try {
			writer.handleStatement(
					ValueFactoryImpl.getInstance().createStatement(s, p, o));
		} catch (RDFHandlerException ex) {
			throw new RuntimeException(ex);
		}
	}
	
	private void checkInput(Resource s, URI p, Value o) {
		if(s==null)throw new IllegalArgumentException("Subject value is null");
		if(p ==null)throw new IllegalArgumentException("Predicate value is null");
		if(o==null) throw new IllegalArgumentException("Object value is null");
	}

	public void receiveLabel(String label, ExtractionContext context) {
		// ignore metadata
	}

	public void close() {
		try {
			writer.endRDF();
		} catch (RDFHandlerException e) {
			throw new RuntimeException(e);
		}
	}
}
{'fraction_non_alphanumeric': 0.10545677498467199, 'fraction_numerical': 0.002452483139178418, 'mean_word_length': 4.530508474576271, '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': '935832', 'n_tokens_mistral': 1146, 'n_tokens_neox': 1012, 'n_words': 230}