<commit_before>package org.sitenv.vocabularies.loader.snomed;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;

import org.apache.log4j.Logger;
import org.sitenv.vocabularies.constants.VocabularyConstants;
import org.sitenv.vocabularies.loader.Loader;
import org.sitenv.vocabularies.loader.LoaderManager;
import org.sitenv.vocabularies.model.VocabularyModelDefinition;
import org.sitenv.vocabularies.model.impl.RxNormModel;
import org.sitenv.vocabularies.model.impl.SnomedModel;
import org.sitenv.vocabularies.repository.VocabularyRepository;

import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;

public class SnomedLoader implements Loader {

	private static Logger logger = Logger.getLogger(SnomedLoader.class);
	

	static {
		LoaderManager.getInstance()
				.registerLoader(VocabularyConstants.SNOMEDCT_CODE_NAME, SnomedLoader.class);
		System.out.println("Loaded: " + VocabularyConstants.SNOMEDCT_CODE_NAME + "(" + VocabularyConstants.SNOMEDCT_CODE_SYSTEM + ")");
		

		if (VocabularyRepository.getInstance().getVocabularyMap() == null)
		{
			VocabularyRepository.getInstance().setVocabularyMap(new HashMap<String,VocabularyModelDefinition>());
		}
		
		VocabularyModelDefinition snomed = new VocabularyModelDefinition(SnomedModel.class, VocabularyConstants.SNOMEDCT_CODE_SYSTEM);
			

		VocabularyRepository.getInstance().getVocabularyMap().put(VocabularyConstants.SNOMEDCT_CODE_SYSTEM, snomed);
		
	}

	public void load(File file) {

		OObjectDatabaseTx dbConnection = VocabularyRepository.getInstance().getInactiveDbConnection();
		
		logger.debug("Loading SNOMED File: " + file.getName());

		BufferedReader br = null;
		
		try {
			logger.info("Truncating SnomedModel Datastore...");
			
			VocabularyRepository.truncateModel(dbConnection, SnomedModel.class);
			
			logger.info(dbConnection.getName() + ".SnomedModel Datastore Truncated... records remaining: " + VocabularyRepository.getRecordCount(dbConnection, SnomedModel.class));
			
			
			int count = 0;

			br = new BufferedReader(new FileReader(file));
			String available;
			while ((available = br.readLine()) != null) {
				if (count++ == 0) {
					continue; // skip header row
				} else {

					String[] line = available.split("\t");
					
					SnomedModel model = dbConnection.newInstance(SnomedModel.class);
					model.setCode(line[0].toUpperCase());
					model.setDisplayName(line[2].toUpperCase());
					
					dbConnection.save(model);
				}


			}
			VocabularyRepository.updateIndexProperties(dbConnection, SnomedModel.class);
			
			<commit_msg>Fixed an error made in the Snomed Loader<commit_after>package org.sitenv.vocabularies.loader.snomed;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.HashMap;

import org.apache.log4j.Logger;
import org.sitenv.vocabularies.constants.VocabularyConstants;
import org.sitenv.vocabularies.loader.Loader;
import org.sitenv.vocabularies.loader.LoaderManager;
import org.sitenv.vocabularies.model.VocabularyModelDefinition;
import org.sitenv.vocabularies.model.impl.RxNormModel;
import org.sitenv.vocabularies.model.impl.SnomedModel;
import org.sitenv.vocabularies.repository.VocabularyRepository;

import com.orientechnologies.orient.core.sql.OCommandSQL;
import com.orientechnologies.orient.object.db.OObjectDatabaseTx;

public class SnomedLoader implements Loader {

	private static Logger logger = Logger.getLogger(SnomedLoader.class);
	

	static {
		LoaderManager.getInstance()
				.registerLoader(VocabularyConstants.SNOMEDCT_CODE_NAME, SnomedLoader.class);
		System.out.println("Loaded: " + VocabularyConstants.SNOMEDCT_CODE_NAME + "(" + VocabularyConstants.SNOMEDCT_CODE_SYSTEM + ")");
		

		if (VocabularyRepository.getInstance().getVocabularyMap() == null)
		{
			VocabularyRepository.getInstance().setVocabularyMap(new HashMap<String,VocabularyModelDefinition>());
		}
		
		VocabularyModelDefinition snomed = new VocabularyModelDefinition(SnomedModel.class, VocabularyConstants.SNOMEDCT_CODE_SYSTEM);
			

		VocabularyRepository.getInstance().getVocabularyMap().put(VocabularyConstants.SNOMEDCT_CODE_SYSTEM, snomed);
		
	}

	public void load(File file) {

		OObjectDatabaseTx dbConnection = VocabularyRepository.getInstance().getInactiveDbConnection();
		
		logger.debug("Loading SNOMED File: " + file.getName());

		BufferedReader br = null;
		
		try {
			logger.info("Truncating SnomedModel Datastore...");
			
			VocabularyRepository.truncateModel(dbConnection, SnomedModel.class);
			
			logger.info(dbConnection.getName() + ".SnomedModel Datastore Truncated... records remaining: " + VocabularyRepository.getRecordCount(dbConnection, SnomedModel.class));
			
			
			int count = 0;

			br = new BufferedReader(new FileReader(file));
			String available;
			while ((available = br.readLine()) != null) {
				if (count++ == 0) {
					continue; // skip header row
				} else {

					String[] line = available.split("\t");
					
					SnomedModel model = dbConnection.newInstance(SnomedModel.class);
					model.setCode(line[4].toUpperCase());
					model.setDisplayName(line[2].toUpperCase());
					
					dbConnection.save(model);
				}


			}
			VocabularyRepository.updateIndexProperties(dbConnection, SnomedModel.class);
			
			
{'fraction_non_alphanumeric': 0.1097494055240534, 'fraction_numerical': 0.0018291567587342234, 'mean_word_length': 5.089086859688196, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '2020076', 'n_tokens_mistral': 1934, 'n_tokens_neox': 1672, 'n_words': 253}