Skip to content

Commit

Permalink
Merge pull request huaban#131 from cctyl/master
Browse files Browse the repository at this point in the history
兼容jdk1.8
  • Loading branch information
piaolingxue authored Mar 24, 2023
2 parents 57d2733 + e3684cd commit 118cc63
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 89 deletions.
8 changes: 4 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<developers>
Expand Down Expand Up @@ -67,8 +67,8 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
Expand Down Expand Up @@ -158,7 +158,7 @@
</plugins>
</pluginManagement>
</build>


<profiles>
<profile>
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/com/huaban/analysis/jieba/JiebaSegmenter.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.huaban.analysis.jieba;

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
Expand Down Expand Up @@ -30,7 +31,7 @@ public void initUserDict(String[] paths){
wordDict.init(paths);

}

private Map<Integer, List<Integer>> createDAG(String sentence) {
Map<Integer, List<Integer>> dag = new HashMap<Integer, List<Integer>>();
DictSegment trie = wordDict.getTrie();
Expand Down Expand Up @@ -176,7 +177,7 @@ public List<SegToken> process(String paragraph, SegMode mode) {


/*
*
*
*/
public List<String> sentenceProcess(String sentence) {
List<String> tokens = new ArrayList<String>();
Expand Down
161 changes: 78 additions & 83 deletions src/main/java/com/qianxinyao/analysis/jieba/keyword/Keyword.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,99 +6,94 @@
* @github https://github.com/bluemapleman
* @date Oct 20, 2018
*/
public class Keyword implements Comparable<Keyword>
{
private double tfidfvalue;
private String name;
/**
* @return the tfidfvalue
*/
public double getTfidfvalue()
{
return tfidfvalue;
}
public class Keyword implements Comparable<Keyword> {
private double tfidfvalue;
private String name;

/**
* @param tfidfvalue the tfidfvalue to set
*/
public void setTfidfvalue(double tfidfvalue)
{
this.tfidfvalue = tfidfvalue;
}
/**
* @return the tfidfvalue
*/
public double getTfidfvalue() {
return tfidfvalue;
}

/**
* @param tfidfvalue the tfidfvalue to set
*/
public void setTfidfvalue(double tfidfvalue) {
this.tfidfvalue = tfidfvalue;
}

/**
* @return the name
*/
public String getName()
{
return name;
}

/**
* @return the name
*/
public String getName() {
return name;
}

/**
* @param name the name to set
*/
public void setName(String name)
{
this.name = name;
}

/**
* @param name the name to set
*/
public void setName(String name) {
this.name = name;
}

public Keyword(String name,double tfidfvalue)
{
this.name=name;
// tfidf值只保留3位小数
this.tfidfvalue=(double)Math.round(tfidfvalue*10000)/10000;
}

/**
* 为了在返回tdidf分析结果时,可以按照值的从大到小顺序返回,故实现Comparable接口
*/
@Override
public int compareTo(Keyword o)
{
return this.tfidfvalue-o.tfidfvalue>0?-1:1;
}

/**
* 重写hashcode方法,计算方式与原生String的方法相同
*/
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
long temp;
temp = Double.doubleToLongBits(tfidfvalue);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}
public Keyword(String name, double tfidfvalue) {
this.name = name;
// tfidf值只保留3位小数
this.tfidfvalue = (double) Math.round(tfidfvalue * 10000) / 10000;
}

@Override
public boolean equals(Object obj)
{
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Keyword other = (Keyword) obj;
if (name == null)
{
if (other.name != null)
return false;
}
else if (!name.equals(other.name))
return false;
/**
* 为了在返回tdidf分析结果时,可以按照值的从大到小顺序返回,故实现Comparable接口
*/
@Override
public int compareTo(Keyword o) {
if (this.tfidfvalue > o.tfidfvalue) {
return -1;
} else if (this.tfidfvalue == o.tfidfvalue) {
return 0;
} else {
return -1;
}
}

/**
* 重写hashcode方法,计算方式与原生String的方法相同
*/
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((name == null) ? 0 : name.hashCode());
long temp;
temp = Double.doubleToLongBits(tfidfvalue);
result = prime * result + (int) (temp ^ (temp >>> 32));
return result;
}

@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Keyword other = (Keyword) obj;
if (name == null) {
if (other.name != null)
return false;
} else if (!name.equals(other.name))
return false;
// if (Double.doubleToLongBits(tfidfvalue) != Double.doubleToLongBits(other.tfidfvalue))
// return false;
return true;
}



return true;
}


}

0 comments on commit 118cc63

Please sign in to comment.