<commit_before>package fr.insee.stamina.nsis;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.SKOS;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.google.maps.GeoApiContext;
import com.google.maps.GeocodingApi;
import com.google.maps.model.AddressComponent;
import com.google.maps.model.AddressComponentType;
import com.google.maps.model.GeocodingResult;
import com.google.maps.model.Geometry;

/**
 * The <code>NSISModelMaker</code> class creates and saves the Jena models corresponding to the list of NSIs.
 * 
 * This program uses the ORG ontology published by the W3C.
 * 
 * @see <a href="https://www.w3.org/TR/vocab-org/">https://www.w3.org/TR/vocab-org/</a>
 * @author <NAME>
 * @version 0.3, 11 Nov 2016
 */
public class NSISModelMaker {

	/** Input TSV file */
	static String NSIS_TXT = "src/main/resources/data/nsis.csv";

	/** File containing the Google Maps API key (must be of type Server key) */
	public static String API_KEY_FILE = "src/main/resources/data/gm-api-key.txt";

	/** URL of the ORG ontology in Turtle format */
	public static String ORG_ONTO_URL = "http://www.w3.org/ns/org.ttl";
	/** Base URI for the ORG ontology */
	public static String ORG_BASE_URI = "http://www.w3.org/ns/org#";

	/** Base URL of the vCard ontology */
	public static String VCARD_BASE_URI = "http://www.w3.org/2006/vcard/ns#";

	/** Output file: Turtle file containing the NSI individuals */
	public static String NSIS_TTL = "src/main/resources/data/nsis.ttl";

	/** Base URI for the individuals (this is a temporary scheme) */
	public static String BASE_URI = "http://id.unece.org/nsi/";

	/** Log4J2 logger */
	private static final Logger logger = LogManager.getLogger(NSISModelMaker.class);

	/** Jena model for vocabulary components */
	static OntModel ontologyModel = null;
	/** Jena model for information on NSIs */
	static Model nsisModel = null;

	// Maximum number of input lines that will be treated (can be used for tests, careful with the header line)
	static int MAX_INPUT_LINES = 1000;

	public static void main(String[] args) {

		// Read the Google Maps API key from the file and initialize the API context
		String apiKey;
		try {
			apiKey = new String(Files.readAllBytes(Paths.get(API_KEY_FILE)));
		} catch (IOException e) {
			logger.fatal("An exception occurred while reading the Google Maps API key", e);
			return;
		}
		GeoApiContext context = new GeoApiContext().setApiKey(apiKey);
		logger.info("Google Maps API key read from " + API_KEY_FILE);

		// Initialize the ontology model, populate it with the ORG ontology, extract some useful ORG components, add useful components from other ontologies
		ontologyModel = ModelFactory.createOntologyModel();
		ontologyModel.read(ORG_ONTO_URL, "TTL");
		Resource orgClass = ontologyModel.getOntClass(ORG_BASE_URI + "Organization");
		Resource siteClass = ontologyModel.getOntClass(ORG_BASE_URI + "Site");
		Property siteProperty = ontologyModel.getOntProperty(ORG_BASE_URI + "hasSite");<commit_msg>Google Maps API context now uses 'builder' pattern<commit_after>package fr.insee.stamina.nsis;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;
import org.apache.commons.csv.CSVRecord;
import org.apache.jena.ontology.OntModel;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.ModelFactory;
import org.apache.jena.rdf.model.Property;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.vocabulary.SKOS;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.google.maps.GeoApiContext;
import com.google.maps.GeocodingApi;
import com.google.maps.model.AddressComponent;
import com.google.maps.model.AddressComponentType;
import com.google.maps.model.GeocodingResult;
import com.google.maps.model.Geometry;

/**
 * The <code>NSISModelMaker</code> class creates and saves the Jena models corresponding to the list of NSIs.
 * 
 * This program uses the ORG ontology published by the W3C.
 * 
 * @see <a href="https://www.w3.org/TR/vocab-org/">https://www.w3.org/TR/vocab-org/</a>
 * @author <NAME>
 * @version 0.3, 11 Nov 2016
 */
public class NSISModelMaker {

	/** Input TSV file */
	static String NSIS_TXT = "src/main/resources/data/nsis.csv";

	/** File containing the Google Maps API key (must be of type Server key) */
	public static String API_KEY_FILE = "src/main/resources/data/gm-api-key.txt";

	/** URL of the ORG ontology in Turtle format */
	public static String ORG_ONTO_URL = "http://www.w3.org/ns/org.ttl";
	/** Base URI for the ORG ontology */
	public static String ORG_BASE_URI = "http://www.w3.org/ns/org#";

	/** Base URL of the vCard ontology */
	public static String VCARD_BASE_URI = "http://www.w3.org/2006/vcard/ns#";

	/** Output file: Turtle file containing the NSI individuals */
	public static String NSIS_TTL = "src/main/resources/data/nsis.ttl";

	/** Base URI for the individuals (this is a temporary scheme) */
	public static String BASE_URI = "http://id.unece.org/nsi/";

	/** Log4J2 logger */
	private static final Logger logger = LogManager.getLogger(NSISModelMaker.class);

	/** Jena model for vocabulary components */
	static OntModel ontologyModel = null;
	/** Jena model for information on NSIs */
	static Model nsisModel = null;

	// Maximum number of input lines that will be treated (can be used for tests, careful with the header line)
	static int MAX_INPUT_LINES = 1000;

	public static void main(String[] args) {

		// Read the Google Maps API key from the file and initialize the API context
		String apiKey;
		try {
			apiKey = new String(Files.readAllBytes(Paths.get(API_KEY_FILE)));
		} catch (IOException e) {
			logger.fatal("An exception occurred while reading the Google Maps API key", e);
			return;
		}
		GeoApiContext context = new GeoApiContext.Builder().apiKey(apiKey).build();
		logger.info("Google Maps API key read from " + API_KEY_FILE);

		// Initialize the ontology model, populate it with the ORG ontology, extract some useful ORG components, add useful components from other ontologies
		ontologyModel = ModelFactory.createOntologyModel();
		ontologyModel.read(ORG_ONTO_URL, "TTL");
		Resource orgClass = ontologyModel.getOntClass(ORG_BASE_URI + "Organization");
		Resource siteClass = ontologyModel.getOntClass(ORG_BASE_URI + "Site");
		Property siteProperty = ontologyModel.getOntProperty(ORG_BASE_URI + "hasSite");
{'fraction_non_alphanumeric': 0.11470911086717893, 'fraction_numerical': 0.007135016465422613, 'mean_word_length': 4.464017991004498, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 4, 'lorem ipsum': 0, 'www.': 10, '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': '4736676', 'n_tokens_mistral': 2474, 'n_tokens_neox': 2332, 'n_words': 646}