Skip to content

Commit b2ead48

Browse files
authored
fix thread problem (#176)
1 parent fa86fe9 commit b2ead48

File tree

7 files changed

+53
-25
lines changed

7 files changed

+53
-25
lines changed

CHANGES.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Change Log
2+
3+
* 1.1.3
4+
* 新增自定义地址设置
5+
* 1.1.4
6+
* 修复一些匹配错误的bug
7+
* 1.1.6
8+
* 升级地址库和包版本, 修复一些匹配错误的地址
9+
* 1.2.0
10+
* geocoding项目转移到组织:bitlap/geocoding
11+
* 1.3.0
12+
* 新增自定义地址文件库配置参数
13+
* 添加自定义地址新增replace参数
14+
* 1.3.1
15+
* 修复normalizing方法多线程调用报错的问题

README.md

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
<!-- 从1.2.0开始迁移到bitlap,原groupId: io.patamon.geocoding -->
1919
<groupId>org.bitlap</groupId>
2020
<artifactId>geocoding</artifactId>
21-
<version>1.3.0</version>
21+
<version>1.3.1</version>
2222
</dependency>
2323
</dependencies>
2424
```
@@ -176,17 +176,12 @@ Address(
176176

177177
## Release Log
178178

179-
* 1.1.3
180-
* 新增自定义地址设置
181-
* 1.1.4
182-
* 修复一些匹配错误的bug
183-
* 1.1.6
184-
* 升级地址库和包版本, 修复一些匹配错误的地址
185-
* 1.2.0
186-
- geocoding项目转移到组织:bitlap/geocoding
187-
* 1.3.0
188-
* 新增自定义地址文件库配置参数
189-
* 添加自定义地址新增replace参数
179+
[Change Log](./CHANGES.md)
180+
181+
182+
## LICENSE
183+
184+
MIT
190185

191186
[1]:https://lsp.wuliu.taobao.com/locationservice/addr/output_address_town.do
192187
[2]:http://www.stats.gov.cn/tjsj/tjbz/tjyqhdmhcxhfdm/2015/index.html

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
<groupId>org.bitlap</groupId>
88
<artifactId>geocoding</artifactId>
9-
<version>1.3.0</version>
9+
<version>1.3.1</version>
1010

1111
<name>geocoding</name>
1212
<description>地理编码技术,提供地址标准化和相似度计算。</description>
@@ -293,7 +293,7 @@
293293
<plugin>
294294
<groupId>org.sonatype.plugins</groupId>
295295
<artifactId>nexus-staging-maven-plugin</artifactId>
296-
<version>1.6.12</version>
296+
<version>1.6.13</version>
297297
<extensions>true</extensions>
298298
<configuration>
299299
<serverId>central</serverId>

src/main/java/org/bitlap/geocoding/core/Context.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package org.bitlap.geocoding.core
33
import org.bitlap.geocoding.core.impl.DefaultAddressInterpreter
44
import org.bitlap.geocoding.core.impl.DefaultAddressPersister
55
import org.bitlap.geocoding.core.impl.DefaultRegionCache
6-
import org.bitlap.geocoding.core.impl.RegionInterpreterVisitor
76
import org.bitlap.geocoding.core.impl.SimilarityComputer
87

98
/**
@@ -16,8 +15,7 @@ open class Context(
1615
val dataClassPath: String,
1716
val strict: Boolean,
1817
val persister: AddressPersister = DefaultAddressPersister(DefaultRegionCache(dataClassPath)),
19-
val visitor: TermIndexVisitor = RegionInterpreterVisitor(persister, strict),
20-
val interpreter: AddressInterpreter = DefaultAddressInterpreter(persister, visitor),
18+
val interpreter: AddressInterpreter = DefaultAddressInterpreter(persister, strict),
2119
val computer: Computer = SimilarityComputer(),
2220
) {
2321

src/main/java/org/bitlap/geocoding/core/impl/DefaultAddressInterpreter.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import java.util.regex.Pattern
2121
* Created by IceMimosa
2222
* Date: 2017/1/17
2323
*/
24-
open class DefaultAddressInterpreter(val persister: AddressPersister, val visitor: TermIndexVisitor) : AddressInterpreter {
24+
open class DefaultAddressInterpreter(val persister: AddressPersister, val strict: Boolean) : AddressInterpreter {
2525

2626
private var indexBuilder: TermIndexBuilder? = null
2727
private val ignoringRegionNames = mutableListOf(
@@ -207,7 +207,7 @@ open class DefaultAddressInterpreter(val persister: AddressPersister, val visito
207207
* 将`脏`地址进行标准化处理, 解析成 [AddressEntity]
208208
*/
209209
override fun interpret(address: String?): AddressEntity? {
210-
return interpret(address, visitor)
210+
return interpret(address, RegionInterpreterVisitor(persister, strict))
211211
}
212212

213213
private fun interpret(address: String?, visitor: TermIndexVisitor): AddressEntity? {

src/main/java/org/bitlap/geocoding/core/impl/SimilarityComputer.kt

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ import org.bitlap.geocoding.utils.isNumericChars
2525
/**
2626
* Desc: 相似度算法相关逻辑
2727
*
28-
* 1. >>>>> 关于 TF-IDF
29-
* TC: 词数 Term Count, 某个词在文档中出现的次数
30-
* TF: 词频 Term Frequency, 某个词在文档中出现的频率. TF = 该词在文档中出现的次数 / 该文档的总词数
31-
* IDF: 逆文档词频 Inverse Document Frequency. IDF = log( 语料库文档总数 / ( 包含该词的文档数 + 1 ) ). 分母加1是为了防止分母出现0的情况
32-
* TF-IDF: 词条的特征值, TF-IDF = TF * IDF
28+
* * 关于 TF-IDF
29+
* * TC: 词数 Term Count, 某个词在文档中出现的次数
30+
* * TF: 词频 Term Frequency, 某个词在文档中出现的频率. TF = 该词在文档中出现的次数 / 该文档的总词数
31+
* * IDF: 逆文档词频 Inverse Document Frequency. IDF = log( 语料库文档总数 / ( 包含该词的文档数 + 1 ) ). 分母加1是为了防止分母出现0的情况
32+
* * TF-IDF: 词条的特征值, TF-IDF = TF * IDF
3333
*
3434
* Mail: chk19940609@gmail.com
3535
* Created by IceMimosa

src/test/java/org/bitlap/geocoding/TestSimilarity.kt

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package org.bitlap.geocoding
22

33
import org.junit.Test
4+
import java.util.concurrent.Callable
5+
import java.util.concurrent.Executors
46

57
/**
68
* Desc: 测试相似度
@@ -49,4 +51,22 @@ open class TestSimilarity {
4951

5052
println("相似度结果分析 >>>>>>>>> " + Geocoding.similarityWithResult(addr1, addr2))
5153
}
52-
}
54+
55+
@Test
56+
fun test_similarity_threads() {
57+
val pool = Executors.newFixedThreadPool(10)
58+
59+
val addr1 = "中国湖南郴州宜章县梅田镇【梅田镇】(梅田镇附近)"
60+
val addr2 = "湖南省郴州市宜章县梅田镇上寮村2组"
61+
62+
(1 .. 1000).map {
63+
pool.submit(Callable {
64+
Geocoding.similarity(addr1, addr2)
65+
})
66+
}.forEach {
67+
val r = it.get()
68+
assert(0.8164965809277261 == r)
69+
}
70+
pool.shutdown()
71+
}
72+
}

0 commit comments

Comments
 (0)