add ChangeSynonyms
This commit is contained in:
parent
ba255a345f
commit
1b4d008796
|
|
@ -0,0 +1,20 @@
|
|||
#!/bin/bash
|
||||
|
||||
find ./target/classes -name "*.properties"|xargs rm -f
|
||||
find ./target/classes -name "*.xml"|xargs rm -f
|
||||
find ./target/classes -name "*.dic"|xargs rm -f
|
||||
|
||||
#export CLASSPATH=$CURR_DIR/lib:$CURR_DIR:$JAVA_HOME/lib:$JAVA_HOME/jre/lib
|
||||
|
||||
tmp='./target/classes':$tmp
|
||||
tmp='./target/Project_Match-0.0.1-SNAPSHOT-jar-with-dependencies-without-resources/*':$tmp
|
||||
tmp='./bin/resources':$tmp
|
||||
CLASSPATH=$tmp:$CLASSPATH
|
||||
|
||||
|
||||
echo $CLASSPATH
|
||||
JVM_ARGS="-Xmn98m -Xmx512m -Xms512m -XX:NewRatio=4 -XX:SurvivorRatio=4 -XX:MaxTenuringThreshold=2"
|
||||
#echo JVM_ARGS=$JVM_ARGS
|
||||
#ulimit -n 400000
|
||||
#echo "" > nohup.out
|
||||
java $JVM_ARGS -classpath $CLASSPATH com.ossean.ChangeSynonyms >>log/change_synonyms.log 2>&1 &
|
||||
|
|
@ -0,0 +1,97 @@
|
|||
package com.ossean;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import com.ossean.databaseSource.DBSource;
|
||||
import com.ossean.model.OpenSourceProject;
|
||||
|
||||
|
||||
@Component
|
||||
public class ChangeSynonyms {
|
||||
|
||||
Logger logger = Logger.getLogger(this.getClass());
|
||||
|
||||
@Resource
|
||||
private DBSource dbSource;
|
||||
|
||||
private static String sourceTableName = "open_source_projects";
|
||||
private static String targetTableName = "synonyms";
|
||||
private static String pointerTableName = "edd_pointers";
|
||||
|
||||
private static int batchSize = 1000;
|
||||
|
||||
|
||||
//读指针
|
||||
public int readPointer(String table, String source, String target){
|
||||
int pointer = 1;
|
||||
//pointer的初始值应该从数据库中读出最小的id
|
||||
try {
|
||||
pointer = dbSource.getMinId(source);
|
||||
} catch (Exception e){
|
||||
//表示表中没有数据
|
||||
logger.info("No item in this table");
|
||||
dbSource.insertPointer(table, source, target, 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
try {
|
||||
pointer = dbSource.getPointer(table, source, target);
|
||||
} catch(Exception e) {
|
||||
logger.info("No such pointer! Create one");
|
||||
dbSource.insertPointer(table, source, target, pointer);
|
||||
}
|
||||
return pointer;
|
||||
}
|
||||
|
||||
|
||||
public void start(){
|
||||
//读取对应的指针
|
||||
int startId = readPointer(pointerTableName, sourceTableName, targetTableName);
|
||||
List<OpenSourceProject> openSourceProjectList = dbSource.getOpenSourceProjectList(sourceTableName, startId, batchSize);
|
||||
|
||||
if(openSourceProjectList.size() == 0){
|
||||
//表示程序执行完成
|
||||
logger.info("程序执行完成");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
for(OpenSourceProject project:openSourceProjectList){
|
||||
String synonyms = project.getSynonyms();
|
||||
logger.info("处理项目:" + project.getId());
|
||||
//判断synonyms是否需要修改
|
||||
if(synonyms == null || "".equals(synonyms)){
|
||||
dbSource.updatePointer(pointerTableName, sourceTableName, targetTableName, project.getId() + 1); //更新指针
|
||||
continue; //表示没有同义词 不需要修改
|
||||
}
|
||||
|
||||
if(synonyms.indexOf("<") >= 0){
|
||||
dbSource.updatePointer(pointerTableName, sourceTableName, targetTableName, project.getId() + 1); //更新指针
|
||||
continue; //表示存储的是正确的结果 不需要修改
|
||||
}else{
|
||||
logger.info("修改项目:" + project.getId());
|
||||
String result = "";
|
||||
String[] array = synonyms.split(",");
|
||||
for(String s:array){
|
||||
result = result + "<" + s + ">,";
|
||||
}
|
||||
result = result.substring(0, result.length() - 1);
|
||||
dbSource.updateSynonyms(sourceTableName, result, project.getId());
|
||||
dbSource.updatePointer(pointerTableName, sourceTableName, targetTableName, project.getId() + 1); //更新指针
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static void main(String[] args){
|
||||
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:/applicationContext*.xml");
|
||||
ChangeSynonyms Main = applicationContext.getBean(ChangeSynonyms.class);
|
||||
Main.start();
|
||||
}
|
||||
}
|
||||
|
|
@ -11,6 +11,7 @@ import org.apache.ibatis.annotations.Update;
|
|||
import com.ossean.model.EddProjects;
|
||||
import com.ossean.model.EddRelations;
|
||||
import com.ossean.model.GatherProjectsModel;
|
||||
import com.ossean.model.OpenSourceProject;
|
||||
import com.ossean.model.Synonymmings;
|
||||
import com.ossean.model.Synonyms;
|
||||
import com.ossean.model.Taggings;
|
||||
|
|
@ -175,4 +176,13 @@ public interface DBSource {
|
|||
@Update("update ${table} set gather_projects_ids=#{gather_projects_ids} where id=#{id}")
|
||||
public void updateEddRelationGatherProjectsIds(@Param("table") String table, @Param("id") int id, @Param("gather_projects_ids") String gather_projects_ids);
|
||||
|
||||
|
||||
//更新open_source_projects表中每条记录的synonyms字段
|
||||
@Update("update ${table} set synonyms=#{synonyms} where id=#{id}")
|
||||
public void updateSynonyms(@Param("table") String table, @Param("synonyms") String synonyms, @Param("id") int id);
|
||||
|
||||
|
||||
//读取open_source_projects表中的记录
|
||||
@Select("select * from ${table} where id>=#{startId} limit #{size}")
|
||||
public List<OpenSourceProject> getOpenSourceProjectList(@Param("table") String table, @Param("startId") int startId, @Param("size") int size);
|
||||
}
|
||||
Loading…
Reference in New Issue