<commit_before>/**
* 
* 
* 
*/

import java.lang.String;
import java.lang.StringBuilder;
import java.util.ArrayList;

public class LongestCommonSubseq<T>{
	final private T[] scr;
	final private T[] dst;

	// array of indexes for each
	private int[] deleted;
	private int[] added;
	private int[] changed; 
	private int[] match;

	private void 

	
	public LongestCommonSubseq(final T[] scr, final T[] dst){
		this.scr = scr;
		this.dst = dst;
		//...
	}
	public LongestCommonSubseq(final iterable<T> scr, final iterable<T> dst){
		this.scr = scr;
		this.dst = dst;
		//...
	}
	public String toString(){
		//TODO
		return null;
	}
	public static void main(String[] args){
		String src, dst;
		if(args.length >= 2){/*
			if(args[0].equals("-f")){

			}
			else
			{
				
			}*/
			src = args[0];
			dst = args[1];
		}
		else{
			//error msg.
		}

		LongestCommonSubseq<Character> lcs;
		ArrayList<Character> tmpArrSrc = new ArrayList<Character>(src.length());
		ArrayList<Character> tmpArrDst = new ArrayList<Character>(dst.length());

		for(char c : src.toCharArr()){
			tmpArrSrc.add(c);
		}
		for(char c : dst.toCharArr()){
			tmpArrDst.add(c);
		}
		lcs = new LongestCommonSubseq(tmpArrSrc, tmpArrDst);


	}
	
}

<commit_msg>Commit : core Algorithm(Longist Common Subsequence)<commit_after>/*
 * LongestCommonSubseq.java : 
 * find the LCS of two sequences of any typed data(such that can check equivalence - public boolean equals() is implemented)
 * testing with two string arg1, arg2 by
 * java LongestCommonSubseq <arg1> <arg2>
 * also, with option "-f", testing with two files path1, path2 by
 * java LongestCommonSubseq -f <path1> <path2>
 */
import java.lang.String;
import java.lang.StringBuilder;
import java.util.Collection;
import java.util.ArrayList;
import java.util.Arrays;
import java.io.FileReader;

public class LongestCommonSubseq<T>{
	final private T[] source;
	final private T[] target;

	// array of indexes for each...
	private int lenLcs;
	private ArrayList<Integer> lcsIndexSource; // indexes of source
	private ArrayList<Integer> lcsIndexTarget; // indexes of target
	//private int[][] changed; // indexes of source and target; changed[0] is source's; changed[1] is target's

	private void run(){
		int sl = this.source.length;
		int tl = this.target.length;
		int iBegin = 0, iEnd = sl;
		int jBegin = 0, jEnd = tl;
		int cntFront = 0, cntBack = 0;

		//TODO : optimization

		int lenArr[][] = new int[iEnd - iBegin + 1][jEnd - jBegin + 1]; // JAVA initializes this array by 0 automatically.
		int i,j;

		for(i = iBegin + 1; i <= iEnd; i++) {
			for(j = jBegin + 1; j <= jEnd; j++) {
				if(this.source[i - 1].equals(this.target[j - 1])){
					lenArr[i - iBegin][j - jBegin] = lenArr[i - iBegin - 1][j - jBegin - 1] + 1;
				}
				else {
					lenArr[i - iBegin][j - jBegin] 	= (
						lenArr[i - iBegin - 1][j - jBegin] 
						> lenArr[i - iBegin][j - jBegin - 1]
						) 
					? lenArr[i - iBegin - 1][j - jBegin] 
					: lenArr[i - iBegin][j - jBegin - 1]; 
				}
			}
		}

		this.lenLcs = cntFront + lenArr[sl][tl] + cntBack;
		System.out.println(lenLcs);
		if(this.lenLcs > 0){
			this.lcsIndexSource = new ArrayList<Integer>(this.lenLcs);
			this.lcsIndexTarget = new ArrayList<Integer>(this.lenLcs);

			for(i = 0; i < cntFront; i++){
				this.lcsIndexSource.add(new Integer(i));
				this.lcsIndexTarget.add(new Integer(i));
			}

			i = iBegin + 1;
			j = jBegin + 1;
			int cnt = cntFront;

			while(i <= iEnd && j <= jEnd && cnt < this.lenLcs - cntBack){
				System.out.println(i);
				System.out.println(j);
				if(this.source[i - 1].equals(this.target[j - 1])) {
					this.lcsIndexSource.add(new Integer(i - 1));
					this.lcsIndexTarget.add(new Integer(j - 1));	
					if(i < iEnd) i++;
					if(j < jEnd) j++;
					cnt++;
				}				
				else if ( (j == jEnd && i < iEnd) || 
							(lenArr[i - iBegin + 1][j - jBegin] > 	
						 	lenArr[i - iBegin][j - jBegin + 1])
						) 
				{
				 	i++;
				}
				else {
					if(j < jEnd) j++;
				}
				if(j == jEnd) {
					j = 1;
					i++;
				}
			}

			for(i = sl - cntBack, j = tl - cntBack;i < sl && j < tl;){

				this.lcsIndexSource.add(new Integer(i));
				this.lcsIndexSource.add(new Integer(j));

				if(i < sl - 1) {
					i++;
				}
				if(j < tl - 1) {
					j++;
				}
			}

		}
		else
		{
			this.setNullLcs();
		}
	}

	private void setNullLcs(){
		this.lenLcs = 0;
		this.lcsIndexSource = null;
		this.lcsIndexTarget = null;		
	}

	public LongestCommonSubseq(final Collection<T> source, final Collection<T> target) {
		this.source = (source != null) ?  (T[])source.toArray() : null;
		this.target = (target != null) ?  (T[])target.toArray() : null;

		if(this.source == null || this.target == null || source.isEmpty() || target.isEmpty() ) {
			this.setNullLcs();
		}
		else {
			this.run();	
		}
	}

	public ArrayList<T> getLcsList(){
		if(this.lenLcs == 0){
			return null;
		}

		ArrayList<T> list = new ArrayList<T>(this.lenLcs);
		for(int i = 0; i < this.lenLcs; i++){
			list.add(this.source[this.lcsIndexSource.get(i)]);
		}

		return list;
	}

	public String toString(){
		StringBuilder str = new StringBuilder();

		for(int i = 0; i < this.lenLcs; i++){
			str.append(this.source[this.lcsIndexSource.get(i)].toString() + " ");
		}

		return str.toString();
	}

	private static void lcsTestString(String s, String t){
		ArrayList<Character> tmpArrsource = new ArrayList<Character>(s.length());
		ArrayList<Character> tmpArrtarget = new ArrayList<Character>(t.length());

		for(char c : s.toCharArray()){
			tmpArrsource.add(c);
		}
		for(char c : t.toCharArray()){
			tmpArrtarget.add(c);
		}

		LongestCommonSubseq<Character> lcs = new LongestCommonSubseq<Character>(tmpArrsource, tmpArrtarget);
		System.out.println(lcs.toString());
	}
	// private static void lcsTestFile(String sp, String tp){
	// 	try {
	// 		FileReader inS = new FileReader(sp);
	// 		FileReader inT = new FileReader(tp);

	// 	ArrayList<String> s = new ArrayList<String>();
	// 	ArrayList<String> t = new ArrayList<String>();

	// 	StringBuilder tmpStrBl = new StringBuilder();
	// 	int tmpCh = 0;

	// 	while(inS != null && tmpCh != -1){
	// 		while( ( tmpCh = inS.read() ) != '\n'){
	// 			tmpStrBl.append((char)tmpCh);
	// 		}
	// 		tmpStrBl.append('\n');
	// 		s.add(tmpStrBl.toString());
	// 	}
	// 	tmpCh = 0;
	// 	while(inT != null && tmpCh != -1){
	// 		while( ( tmpCh = inT.read() ) != '\n'){
	// 			tmpStrBl.append((char)tmpCh);
	// 		}
	// 		tmpStrBl.append('\n');
	// 		t.add(tmpStrBl.toString());
	// 	}

	// 	LongestCommonSubseq<String> lcs = new LongestCommonSubseq<String>(s,t);
	// 	System.out.println(lcs.toString());
	// 	}
	// 	finally{
	// 		if(inS == )
	// 	}
	// }

	public static void main(String[] args){
		String source = "", target = "";

		if(args.length >= 2){
			// if(args.length >= 3 && args[0].equals("-f")){
			// 	source = args[1];
			// 	target = args[2];
			// 	LongestCommonSubseq.lcsTestFile(source, target);
			// }
			// else {
				source = args[0];
				target = args[1];
				LongestCommonSubseq.lcsTestString(source, target);
			//}
				
		}
		else{
			//error msg.
		}		
	}	
	
}


{'fraction_non_alphanumeric': 0.17183535382012968, 'fraction_numerical': 0.00845785170566676, 'mean_word_length': 2.784, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 43, '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': '6694471', 'n_tokens_mistral': 3104, 'n_tokens_neox': 2684, 'n_words': 596}