<commit_before>package uk.ac.ebi.embl.flatfile.reader.genomeassembly;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.lang3.StringUtils;
import uk.ac.ebi.embl.api.entry.genomeassembly.AssemblyInfoEntry;
import uk.ac.ebi.embl.api.validation.ValidationResult;

public class AssemblyInfoReader extends GCSEntryReader
{
	private final String MESSAGE_KEY_INVALID_FORMAT_ERROR = "invalidlineFormat";
	private final String MESSAGE_KEY_INVALID_VALUE_ERROR = "invalidfieldValue";
	private final String MESSAGE_KEY_INVALID_FIELD_ERROR = "invalidfieldName";

	private static Pattern pattern =Pattern.compile("^(\\w+)\\s+(.+)$");

	AssemblyInfoEntry assemblyInfoEntry = null;
	public AssemblyInfoReader(File file)
	{
		super();
		this.file=file;
	}
	@Override
	public ValidationResult read() throws NumberFormatException, IOException
	{
		assemblyInfoEntry= new AssemblyInfoEntry();
		int lineNumber = 1;
		try(BufferedReader reader = getBufferedReader(file))
		{
			String line;
			while ((line = reader.readLine()) != null)
			{
				line = line.trim();
				if (line.isEmpty()) // Skip empty lines
				{
					continue;
				}

				Matcher matcher = pattern.matcher(line);

				if(matcher.matches() && matcher.groupCount() == 2)
				{
					String field= StringUtils.deleteWhitespace(matcher.group(1).toUpperCase());
					field= field.replaceAll("_","").replaceAll("-","").replaceAll("\\.","");			
					String fieldValue= matcher.group(2).trim();
					switch(field)
					{
					case "ASSEMBLYNAME":
						assemblyInfoEntry.setName(fieldValue);
						break;
					case "COVERAGE":
						assemblyInfoEntry.setCoverage(fieldValue);
						break;
					case "PROGRAM":
						assemblyInfoEntry.setProgram(fieldValue);
						break;
					case "PLATFORM":
						assemblyInfoEntry.setPlatform(fieldValue);
						break;
					case "MINGAPLENGTH":
						if(isInteger(fieldValue))
						  assemblyInfoEntry.setMinGapLength(new Integer(fieldValue));
						else
						  error(lineNumber,MESSAGE_KEY_INVALID_VALUE_ERROR,field,fieldValue);
						break;
					case "MOLECULETYPE":
						if(isValidMoltype(fieldValue))
							assemblyInfoEntry.setMoleculeType(fieldValue);
						else
						    error(lineNumber,MESSAGE_KEY_INVALID_VALUE_ERROR,field,fieldValue);
						break;
					case "SAMPLE":
						 assemblyInfoEntry.setSampleId(fieldValue);
						 break;
					case "STUDY":
					  	 assemblyInfoEntry.setStudyId(fieldValue);
					  	 break;
					default :
						error(lineNumber,MESSAGE_KEY_INVALID_FIELD_ERROR,line);
						break;
					}
					
				} else {
					error(lineNumber,MESSAGE_KEY_INVALID_FORMAT_ERROR,line);
				}
				lineNumber++;<commit_msg>Revert "assembly info read by space"<commit_after>package uk.ac.ebi.embl.flatfile.reader.genomeassembly;

import java.io.BufferedReader;
import java.io.File;
import java.io.IOException;
import org.apache.commons.lang3.StringUtils;
import uk.ac.ebi.embl.api.entry.genomeassembly.AssemblyInfoEntry;
import uk.ac.ebi.embl.api.validation.ValidationResult;

public class AssemblyInfoReader extends GCSEntryReader
{
	private final String MESSAGE_KEY_INVALID_FORMAT_ERROR = "invalidlineFormat";
	private final String MESSAGE_KEY_INVALID_VALUE_ERROR = "invalidfieldValue";
	private final String MESSAGE_KEY_INVALID_FIELD_ERROR = "invalidfieldName";

	AssemblyInfoEntry assemblyInfoEntry = null;
	public AssemblyInfoReader(File file)
	{
		super();
		this.file=file;
	}
	@Override
	public ValidationResult read() throws NumberFormatException, IOException
	{
		assemblyInfoEntry= new AssemblyInfoEntry();
		int lineNumber = 1;
		try(BufferedReader reader = getBufferedReader(file))
		{
			String line;
			while ((line = reader.readLine()) != null)
			{
				line = line.trim();
				if (line.isEmpty()) // Skip empty lines
				{
					continue;
				}
				
				String[] fields = line.trim().split("\\s+",2);
				int numberOfColumns = fields.length;
				if (numberOfColumns != 2 )
				{
					error(lineNumber,MESSAGE_KEY_INVALID_FORMAT_ERROR,line);
				}
				else
				{
					String field= StringUtils.deleteWhitespace(fields[0].toUpperCase());
					field= field.replaceAll("_","").replaceAll("-","").replaceAll("\\.","");			
					String fieldValue= fields[1];
					switch(field)
					{
					case "ASSEMBLYNAME":
						assemblyInfoEntry.setName(fieldValue);
						break;
					case "COVERAGE":
						assemblyInfoEntry.setCoverage(fieldValue);
						break;
					case "PROGRAM":
						assemblyInfoEntry.setProgram(fieldValue);
						break;
					case "PLATFORM":
						assemblyInfoEntry.setPlatform(fieldValue);
						break;
					case "MINGAPLENGTH":
						if(isInteger(fieldValue))
						  assemblyInfoEntry.setMinGapLength(new Integer(fieldValue));
						else
						  error(lineNumber,MESSAGE_KEY_INVALID_VALUE_ERROR,fields[0],fieldValue);
						break;
					case "MOLECULETYPE":
						if(isValidMoltype(fieldValue))
							assemblyInfoEntry.setMoleculeType(fieldValue);
						else
						    error(lineNumber,MESSAGE_KEY_INVALID_VALUE_ERROR,fields[0],fieldValue);
						break;
					case "SAMPLE":
						 assemblyInfoEntry.setSampleId(fieldValue);
						 break;
					case "STUDY":
					  	 assemblyInfoEntry.setStudyId(fieldValue);
					  	 break;
					default :
						error(lineNumber,MESSAGE_KEY_INVALID_FIELD_ERROR,line);
						break;
					}
					
				}
				lineNumber++;
{'fraction_non_alphanumeric': 0.11152278621711745, 'fraction_numerical': 0.0024082993701370877, 'mean_word_length': 3.7194055944055946, 'pattern_counts': {'":': 16, '<': 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': '5941008', 'n_tokens_mistral': 2164, 'n_tokens_neox': 1640, 'n_words': 280}