-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce the similarity as boost functionality to the Word2VecSynonyFilter #12433
Draft
dantuzi
wants to merge
1
commit into
apache:main
Choose a base branch
from
SeaseLtd:word2vec-boost
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+249
−40
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
lucene/core/src/java/org/apache/lucene/analysis/tokenattributes/BoostAttribute.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.lucene.analysis.tokenattributes; | ||
|
||
import org.apache.lucene.util.Attribute; | ||
|
||
/** | ||
* Add this {@link BoostAttribute} if you want to manipulate the token stream in order to update the | ||
* boost associated to a token | ||
* | ||
* <p><b>Please note:</b> This attribute does not work at index time | ||
* | ||
* @lucene.internal | ||
*/ | ||
public interface BoostAttribute extends Attribute { | ||
/** Sets the boost in this attribute */ | ||
public void setBoost(float boost); | ||
/** Retrieves the boost, default is {@code 1.0f}. */ | ||
public float getBoost(); | ||
} |
86 changes: 86 additions & 0 deletions
86
lucene/core/src/java/org/apache/lucene/analysis/tokenattributes/BoostAttributeImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.apache.lucene.analysis.tokenattributes; | ||
|
||
import java.util.Objects; | ||
import org.apache.lucene.util.AttributeImpl; | ||
import org.apache.lucene.util.AttributeReflector; | ||
|
||
/** | ||
* Implementation class for {@link BoostAttribute}. | ||
* | ||
* @lucene.internal | ||
*/ | ||
public final class BoostAttributeImpl extends AttributeImpl implements BoostAttribute { | ||
private float boost = 1.0f; | ||
|
||
/** Initialize this attribute with no boost. */ | ||
public BoostAttributeImpl() {} | ||
|
||
@Override | ||
public void setBoost(float boost) { | ||
if (Float.isFinite(boost) == false || Float.compare(boost, 0f) < 0) { | ||
throw new IllegalArgumentException("boost must be a positive float, got " + boost); | ||
} | ||
this.boost = boost; | ||
} | ||
|
||
@Override | ||
public float getBoost() { | ||
return boost; | ||
} | ||
|
||
@Override | ||
public void clear() { | ||
boost = 1.0f; | ||
} | ||
|
||
@Override | ||
public BoostAttributeImpl clone() { | ||
BoostAttributeImpl clone = (BoostAttributeImpl) super.clone(); | ||
clone.boost = this.boost; | ||
return clone; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object other) { | ||
if (this == other) { | ||
return true; | ||
} | ||
|
||
if (other == null || getClass() != other.getClass()) { | ||
return false; | ||
} | ||
BoostAttributeImpl that = (BoostAttributeImpl) other; | ||
return Float.compare(that.boost, boost) == 0; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(boost); | ||
} | ||
|
||
@Override | ||
public void copyTo(AttributeImpl target) { | ||
((BoostAttribute) target).setBoost(boost); | ||
} | ||
|
||
@Override | ||
public void reflectWith(AttributeReflector reflector) { | ||
reflector.reflect(BoostAttribute.class, "boost", boost); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add a back-compat ctor that doesn't take
similarityAsBoost
, and defaults it tofalse
I guess?