We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent b9a3a58 commit f06520bCopy full SHA for f06520b
src/main/java/com/hankcs/hanlp/mining/word2vec/DocVectorModel.java
@@ -68,17 +68,23 @@ public Vector query(String content)
68
{
69
if (content == null || content.length() == 0) return null;
70
List<Term> termList = NotionalTokenizer.segment(content);
71
- if (termList.isEmpty())
72
- {
73
- return null;
74
- }
75
Vector result = new Vector(dimension());
+ int n = 0;
76
for (Term term : termList)
77
78
Vector vector = wordVectorModel.vector(term.word);
+ if (vector == null)
+ {
+ continue;
79
+ }
80
+ ++n;
81
result.addToSelf(vector);
82
}
- result.divideToSelf(termList.size());
83
+ if (n == 0)
84
85
+ return null;
86
87
+ result.divideToSelf(n);
88
return result;
89
90
0 commit comments