173 lines
6.5 KiB
Java
173 lines
6.5 KiB
Java
package com.ossean;
|
||
|
||
import info.debatty.java.stringsimilarity.*;
|
||
|
||
import java.net.MalformedURLException;
|
||
import java.net.URL;
|
||
import java.util.ArrayList;
|
||
import java.util.List;
|
||
import java.util.regex.Matcher;
|
||
import java.util.regex.Pattern;
|
||
|
||
import javax.annotation.Resource;
|
||
|
||
import org.junit.runner.RunWith;
|
||
import org.junit.Test;
|
||
import org.springframework.beans.factory.annotation.Autowired;
|
||
import org.springframework.beans.factory.annotation.Qualifier;
|
||
import org.springframework.test.context.ContextConfiguration;
|
||
import org.springframework.test.context.junit4.AbstractJUnit4SpringContextTests;
|
||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||
|
||
import com.ossean.dao.DBDest;
|
||
import com.ossean.dao.DBSource;
|
||
import com.ossean.dao.GatherDao;
|
||
import com.ossean.dao2.PlatformProjectDao;
|
||
import com.ossean.model.GatherProjectsModel;
|
||
import com.ossean.model.SourceForgeProject;
|
||
import com.ossean.util.MergeProjectNew2;
|
||
import com.ossean.util.RegexHandler;
|
||
import com.ossean.util.StringHandler;
|
||
|
||
@RunWith(SpringJUnit4ClassRunner.class)
|
||
@ContextConfiguration({"classpath:/applicationContext.xml","classpath:/applicationContext-myBatis.xml"})
|
||
public class MergeProjectNewTest extends AbstractJUnit4SpringContextTests {
|
||
@Resource
|
||
private DBSource dbSource;
|
||
@Resource
|
||
private GatherDao gatherDao;
|
||
@Resource
|
||
private PlatformProjectDao platformProjectDao;
|
||
@Resource
|
||
private DBDest dbDest;
|
||
@Qualifier("mergeProjectNew2")
|
||
@Autowired
|
||
private MergeProjectNew2 mergeProjectNew2;
|
||
@Qualifier("insertSynonyms")
|
||
@Autowired
|
||
private InsertSynonyms insertSynonyms;
|
||
|
||
|
||
private static String pointerTableName = "edd_pointers_17";//记录去重进行到哪个地方了
|
||
private static String sourceTableName = "gather_projects_test";//去重项目的来源,来自汇总程序生成的表
|
||
private static String targetTableName = "edd_relations_17";//去重结果存储位置
|
||
|
||
@Test
|
||
public void testGetSynonyms(){
|
||
|
||
GatherProjectsModel model = gatherDao.selectGPMById(sourceTableName, 959333);
|
||
GatherProjectsModel model2 = gatherDao.selectGPMById(sourceTableName, 100014);
|
||
List<String> sylist = insertSynonyms.getSynonyms(model);
|
||
List<String> sylist2 = insertSynonyms.getSynonyms(model2);
|
||
System.out.println(357644+":"+sylist);
|
||
System.out.println(100014+":"+sylist2);
|
||
|
||
}
|
||
|
||
public static boolean contain2(List<String> inputList, String regex) {
|
||
Pattern p = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
|
||
for(int i=0;i<inputList.size();i++){
|
||
Matcher m = p.matcher(inputList.get(i));
|
||
boolean result = m.find();
|
||
if(result==true){
|
||
System.out.println(inputList.get(i));
|
||
return result;
|
||
}
|
||
}
|
||
return false;
|
||
}
|
||
|
||
@Test
|
||
public void testUrl(){
|
||
URL url;
|
||
try {
|
||
url = new URL("https://www.7-zip.org");//http://sourceforge.net/projects/gsevenzip
|
||
String host = url.getHost();// 获取主机名
|
||
System.out.println("host:"+host);// 结果 blog.csdn.net
|
||
} catch (MalformedURLException e) {
|
||
e.printStackTrace();
|
||
}
|
||
}
|
||
|
||
|
||
@Test
|
||
public void testSimilarity(){
|
||
|
||
String s1 = "Google Map Gps Cell Phone Tracker has a responsive design using twitter bootstrap";
|
||
String s2 = "Track a GPS enabled cell phone on Google maps.";
|
||
GatherProjectsModel model1 = gatherDao.selectGPMById("gather_projects", 515);
|
||
GatherProjectsModel model2 = gatherDao.selectGPMById("gather_projects", 597699);
|
||
String desc1 = StringHandler.getFirstSentence(model1.getDescription());
|
||
String desc2 = StringHandler.getFirstSentence(model2.getDescription());
|
||
NGram ngram = new NGram(4);
|
||
System.out.println(desc1);
|
||
System.out.println(desc2);
|
||
System.out.println(1-ngram.distance(s1,s2));
|
||
// JaroWinkler jw = new JaroWinkler();
|
||
// System.out.println(jw.similarity(desc1, desc2));
|
||
|
||
// LongestCommonSubsequence lcs = new LongestCommonSubsequence();
|
||
// // Will produce 4.0
|
||
// System.out.println(lcs.distance(s1, s2));
|
||
|
||
|
||
}
|
||
|
||
@Test
|
||
public void testComparePrj(){
|
||
GatherProjectsModel model1 = gatherDao.selectGPMById("gather_projects", 1001009);
|
||
GatherProjectsModel model2 = gatherDao.selectGPMById("gather_projects", 939809);
|
||
//boolean isornot = mergeProjectNew.isTheSameAfterTFIDF(model1, model2,false);
|
||
boolean isornot2 = mergeProjectNew2.isTheSame(model1, model2,true);
|
||
NGram ngram = new NGram(4);
|
||
System.out.println("similarity:"+(1-ngram.distance(model1.getDescription(),model2.getDescription())));
|
||
// /System.out.println(isornot);
|
||
System.out.println(isornot2);
|
||
}
|
||
|
||
@Test
|
||
public void testHandleProject(){
|
||
GatherProjectsModel model = gatherDao.selectGPMById("gather_projects_test",6026);//,100014,36707,357644,941234,
|
||
mergeProjectNew2.handleNewProject(model);
|
||
// List<GatherProjectsModel> list = new ArrayList<GatherProjectsModel>();
|
||
// list.add(dbSource.getGatherProjectById("gather_projects_test", 202));
|
||
// list.add(dbSource.getGatherProjectById("gather_projects_test", 515));
|
||
// list.add(dbSource.getGatherProjectById("gather_projects_test", 742));
|
||
// list.add(dbSource.getGatherProjectById("gather_projects_test", 767));
|
||
// for(GatherProjectsModel model1:list){
|
||
// mergeProjectNew2.handleNewProject(model1);
|
||
// }
|
||
}
|
||
|
||
@Test
|
||
public void testLanguage(){
|
||
String language = "C#, PHP, JavaScript, PL/SQL, Java, Objective-C 2.0";
|
||
String aa="<Java>,<PHP>,<C#>";
|
||
System.out.println(StringHandler.compareLanguage(aa,language));
|
||
}
|
||
|
||
@Test
|
||
public void testtest(){
|
||
String [] aa = StringHandler.splitTagsByBracket("<Database><Information Analysis>");
|
||
for(int i=0;i<aa.length;i++)
|
||
System.out.println(aa[i]);
|
||
System.out.println(RegexHandler.extractEngDecimalAndChinese("<java>"));
|
||
}
|
||
|
||
@Test
|
||
public void testPartDao(){
|
||
List<GatherProjectsModel> list = new ArrayList<GatherProjectsModel>();
|
||
list.add(gatherDao.selectGPMById("gather_projects_test", 175414));//sourceforge
|
||
list.add(gatherDao.selectGPMById("gather_projects_test", 788279));
|
||
list.add(gatherDao.selectGPMById("gather_projects_test", 45));//openhub
|
||
list.add(gatherDao.selectGPMById("gather_projects_test", 426360));
|
||
list.add(gatherDao.selectGPMById("gather_projects_test", 471974));
|
||
list.add(gatherDao.selectGPMById("gather_projects_test", 770152));//oschina
|
||
List<GatherProjectsModel> returnlist = mergeProjectNew2.returnDupModelList(gatherDao.selectGPMById("gather_projects_test", 175414),list,true);
|
||
// GatherProjectsModel model = mergeProjectNew2.getUniqueSourceModel(list);
|
||
// System.out.println(model.getName()+" "+model.getName());
|
||
System.out.println(returnlist.size());
|
||
}
|
||
|
||
}
|