-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Improve merge logic to prefer valid year and entry type #13506
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
b136f92
feat: improve merge dialog to prefer better entry type and year (fixe…
ArshKumar84 b6c4809
Update CHANGELOG.md
ArshKumar84 13d4129
Update CHANGELOG.md
ArshKumar84 55e7fe3
Merge branch 'JabRef:main' into fix-for-issue-12549
ArshKumar84 67ff52b
feat: improve merge dialog to prefer better entry type and year (fixe…
ArshKumar84 e515447
Merge remote-tracking branch 'origin/fix-for-issue-12549' into fix-fo…
ArshKumar84 a47a9c2
feat: Improved readability and removed unnecessary method call
ArshKumar84 093dc3c
Merge branch 'JabRef:main' into fix-for-issue-12549
ArshKumar84 927d31c
Apply suggestion from @koppor
ArshKumar84 84fc4a7
Apply suggestion from @koppor
ArshKumar84 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
7 changes: 7 additions & 0 deletions
7
jablib/src/main/java/org/jabref/logic/bibtex/comparator/ComparisonResult.java
This file contains hidden or 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,7 @@ | ||
| package org.jabref.logic.bibtex.comparator; | ||
|
|
||
| public enum ComparisonResult { | ||
| LEFT_BETTER, | ||
| RIGHT_BETTER, | ||
| UNDETERMINED | ||
| } |
12 changes: 12 additions & 0 deletions
12
...ib/src/main/java/org/jabref/logic/bibtex/comparator/FieldValuePlausibilityComparator.java
This file contains hidden or 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,12 @@ | ||
| package org.jabref.logic.bibtex.comparator; | ||
|
|
||
| public abstract class FieldValuePlausibilityComparator { | ||
| /** | ||
| * Compares the plausibility of two field values. | ||
| * | ||
| * @param leftValue value from the library (or candidate) | ||
| * @param rightValue value from the fetcher (or existing record) | ||
| * @return ComparisonResult indicating which field is more plausible: RIGHT_BETTER, LEFT_BETTER, or UNDETERMINED | ||
| */ | ||
| public abstract ComparisonResult compare(String leftValue, String rightValue); | ||
| } |
62 changes: 62 additions & 0 deletions
62
...rc/main/java/org/jabref/logic/bibtex/comparator/YearFieldValuePlausibilityComparator.java
This file contains hidden or 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,62 @@ | ||
| package org.jabref.logic.bibtex.comparator; | ||
|
|
||
| import java.time.Year; | ||
| import java.util.Optional; | ||
| import java.util.regex.Matcher; | ||
| import java.util.regex.Pattern; | ||
|
|
||
| import org.jabref.logic.integrity.YearChecker; | ||
|
|
||
| public class YearFieldValuePlausibilityComparator extends FieldValuePlausibilityComparator { | ||
|
|
||
| private static final Pattern YEAR_PATTERN = Pattern.compile("(\\d{4})"); | ||
|
|
||
| /** | ||
| * Compares the plausibility of two field values. | ||
| * | ||
| * @param leftValue value from the library (or candidate) | ||
| * @param rightValue value from the fetcher (or existing record) | ||
| * @return ComparisonResult indicating which year is more plausible: RIGHT_BETTER, LEFT_BETTER, or UNDETERMINED | ||
| */ | ||
|
|
||
| @Override | ||
| public ComparisonResult compare(String leftValue, String rightValue) { | ||
| YearChecker checker = new YearChecker(); | ||
|
|
||
| boolean leftValid = checker.checkValue(leftValue).isEmpty(); | ||
|
|
||
| if (leftValid) { | ||
| Optional<Integer> leftYear = extractYear(leftValue); | ||
| Optional<Integer> rightYear = extractYear(rightValue); | ||
|
|
||
| boolean leftYearInRange = (leftYear.get() >= 1800) && (leftYear.get() <= Year.now().getValue() + 2); | ||
|
|
||
| if (leftYearInRange) { | ||
| int diff = Math.abs(leftYear.get() - rightYear.get()); | ||
| if (diff > 10) { | ||
| return rightYear.get() > leftYear.get() | ||
| ? ComparisonResult.RIGHT_BETTER | ||
| : ComparisonResult.LEFT_BETTER; | ||
| } | ||
| return ComparisonResult.UNDETERMINED; // years are close, undetermined | ||
| } | ||
| return ComparisonResult.RIGHT_BETTER; | ||
| } | ||
| return ComparisonResult.RIGHT_BETTER; | ||
| } | ||
|
|
||
| /** | ||
| * Extracts the first 4-digit number found in the string. | ||
| * Used to identify year-like values such as "About 2000" or "Published in 1999". | ||
| * | ||
| * @param value the input string possibly containing a year | ||
| * @return Optional containing the 4-digit year if found, otherwise Optional.empty() | ||
| */ | ||
| private Optional<Integer> extractYear(String value) { | ||
| Matcher matcher = YEAR_PATTERN.matcher(value); | ||
| if (matcher.find()) { | ||
| return Optional.of(Integer.parseInt(matcher.group(1))); | ||
| } | ||
| return Optional.empty(); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.