<commit_before>package org.nanopub.trusty;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.zip.GZIPOutputStream;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.rio.RDFHandlerException;
import org.eclipse.rdf4j.rio.RDFParseException;
import org.eclipse.rdf4j.rio.RDFWriter;
import org.eclipse.rdf4j.rio.Rio;
import org.nanopub.MalformedNanopubException;
import org.nanopub.MultiNanopubRdfHandler;
import org.nanopub.MultiNanopubRdfHandler.NanopubHandler;
import org.nanopub.Nanopub;
import org.nanopub.NanopubImpl;
import org.nanopub.NanopubRdfHandler;
import org.nanopub.NanopubUtils;
import org.nanopub.NanopubWithNs;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;

import net.trustyuri.TrustyUriException;
import net.trustyuri.TrustyUriResource;
import net.trustyuri.rdf.RdfFileContent;
import net.trustyuri.rdf.TransformRdf;

public class MakeTrustyNanopub {

	@com.beust.jcommander.Parameter(description = "input-nanopub-file", required = true)
	private String inputFileName;

	@com.beust.jcommander.Parameter(names = "-o", description = "Output file")
	private File outputFile;

	@com.beust.jcommander.Parameter(names = "-r", description = "Resolve cross-nanopub references")
	private boolean resolveCrossRefs = false;

	@com.beust.jcommander.Parameter(names = "-v", description = "Verbose")
	private boolean verbose = false;

	public static void main(String[] args) {
		NanopubImpl.ensureLoaded();
		MakeTrustyNanopub obj = new MakeTrustyNanopub();
		JCommander jc = new JCommander(obj);
		try {
			jc.parse(args);
		} catch (ParameterException ex) {
			jc.usage();
			System.exit(1);
		}
		try {
			obj.run();
		} catch (Exception ex) {
			ex.printStackTrace();
			System.exit(1);
		}
	}

	private void run() throws IOException, RDFParseException, RDFHandlerException,
			MalformedNanopubException, TrustyUriException {
		final Map<Resource,IRI> tempRefMap;
		if (resolveCrossRefs) {
			tempRefMap = new HashMap<>();
		} else {
			tempRefMap = null;
		}
		File inputFile = new File(inputFileName);
		if (outputFile == null) {
			outputFile = new File(inputFile.getParent(), "trusty." + inputFile.getName());
		}
		final OutputStream out;
		if (outputFile.getName().matches(".*\\.(gz|gzip)")) {
			out = new GZIPOutputStream(new FileOutputStream(outputFile));
		} else {
			out = new FileOutputStream(outputFile);
		}
		final RDFFormat format = new TrustyUriResource(inputFile).getFormat(RDFFormat.TRIG);
		MultiNanopubRdfHandler.process(format, inputFile, new NanopubHandler() {

			@Override
			public void handleNanopub(Nanopub np) {
				try {
					np = writeAsTrustyNanopub(np, format, out, tempRefMap);
					if (verbose) {
						System.out.println("Nanopub URI: " + np.getUri());
					}
				} catch (RDFHandlerException | TrustyUriException ex) {<commit_msg>Fix output format of mktrusty<commit_after>package org.nanopub.trusty;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.zip.GZIPOutputStream;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.rio.RDFFormat;
import org.eclipse.rdf4j.rio.RDFHandlerException;
import org.eclipse.rdf4j.rio.RDFParseException;
import org.eclipse.rdf4j.rio.RDFWriter;
import org.eclipse.rdf4j.rio.Rio;
import org.nanopub.MalformedNanopubException;
import org.nanopub.MultiNanopubRdfHandler;
import org.nanopub.MultiNanopubRdfHandler.NanopubHandler;
import org.nanopub.Nanopub;
import org.nanopub.NanopubImpl;
import org.nanopub.NanopubRdfHandler;
import org.nanopub.NanopubUtils;
import org.nanopub.NanopubWithNs;

import com.beust.jcommander.JCommander;
import com.beust.jcommander.ParameterException;

import net.trustyuri.TrustyUriException;
import net.trustyuri.TrustyUriResource;
import net.trustyuri.rdf.RdfFileContent;
import net.trustyuri.rdf.TransformRdf;

public class MakeTrustyNanopub {

	@com.beust.jcommander.Parameter(description = "input-nanopub-file", required = true)
	private String inputFileName;

	@com.beust.jcommander.Parameter(names = "-o", description = "Output file")
	private File outputFile;

	@com.beust.jcommander.Parameter(names = "-r", description = "Resolve cross-nanopub references")
	private boolean resolveCrossRefs = false;

	@com.beust.jcommander.Parameter(names = "-v", description = "Verbose")
	private boolean verbose = false;

	public static void main(String[] args) {
		NanopubImpl.ensureLoaded();
		MakeTrustyNanopub obj = new MakeTrustyNanopub();
		JCommander jc = new JCommander(obj);
		try {
			jc.parse(args);
		} catch (ParameterException ex) {
			jc.usage();
			System.exit(1);
		}
		try {
			obj.run();
		} catch (Exception ex) {
			ex.printStackTrace();
			System.exit(1);
		}
	}

	private void run() throws IOException, RDFParseException, RDFHandlerException,
			MalformedNanopubException, TrustyUriException {
		final Map<Resource,IRI> tempRefMap;
		if (resolveCrossRefs) {
			tempRefMap = new HashMap<>();
		} else {
			tempRefMap = null;
		}
		File inputFile = new File(inputFileName);
		if (outputFile == null) {
			outputFile = new File(inputFile.getParent(), "trusty." + inputFile.getName());
		}
		final OutputStream out;
		if (outputFile.getName().matches(".*\\.(gz|gzip)")) {
			out = new GZIPOutputStream(new FileOutputStream(outputFile));
		} else {
			out = new FileOutputStream(outputFile);
		}
		final RDFFormat inFormat = new TrustyUriResource(inputFile).getFormat(RDFFormat.TRIG);
		final RDFFormat outFormat = new TrustyUriResource(outputFile).getFormat(RDFFormat.TRIG);
		MultiNanopubRdfHandler.process(inFormat, inputFile, new NanopubHandler() {

			@Override
			public void handleNanopub(Nanopub np) {
				try {
					np = writeAsTrustyNanopub(np, outFormat, out, tempRefMap);
					if (verbose) {
						System.out.println("Nanopub URI: " + np.getUri());
					}
				} catch (RDFHandlerException | TrustyUriException ex) {
{'fraction_non_alphanumeric': 0.11641515244841392, 'fraction_numerical': 0.002771789344009855, 'mean_word_length': 5.087160262417995, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1213806', 'n_tokens_mistral': 2437, 'n_tokens_neox': 2203, 'n_words': 421}