Skip to content

Conversation

tushar-2320
Copy link
Contributor

@tushar-2320 tushar-2320 commented Aug 17, 2025

Closes #12974

Mandatory checks

  • I own the copyright of the code submitted and I license it under the MIT license
  • Change in CHANGELOG.md described in a way that is understandable for the average user (if change is visible to the user)
  • Tests created for changes (if applicable)
  • Manually tested changed features in running JabRef (always required)
  • Screenshots added in PR description (if change is visible to the user)
  • Checked developer's documentation: Is the information available and up to date? If not, I outlined it in this pull request.
  • Checked documentation: Is the information available and up to date? If not, I created an issue at https://github.com/JabRef/user-documentation/issues or, even better, I submitted a pull request to the documentation repository.

@tushar-2320 tushar-2320 marked this pull request as draft August 17, 2025 04:54
@tushar-2320 tushar-2320 changed the title initial commit feat:Allowed multiple delimiter in keyword separator field. Aug 17, 2025
@koppor
Copy link
Member

koppor commented Aug 17, 2025

The approach seems to be wrong.

Do test-driven development. Add tests for each fetcher. At least for the one mentioned in the issue.

You can do heuristics. On the fetcher side. Not on the keywords class.

@tushar-2320
Copy link
Contributor Author

can you give me some example for the tests and where is this fetcher located.

@tushar-2320
Copy link
Contributor Author

can you give me some example for the tests and where is this fetcher located.

@koppor @subhramit

@InAnYan
Copy link
Member

InAnYan commented Aug 18, 2025

It's in the jablib project.
In src/test. src/test/java classes generally follow the same "paths" as in src/main/java. So, if you want to find tests for src/main/java/a/b/c.java, then it's typically at src/test/java/a/b/cTest.java

@tushar-2320
Copy link
Contributor Author

@calixtus @koppor I think I have refactored too much. is this the way?

@jabref-machine
Copy link
Collaborator

Your pull request conflicts with the target branch.

Please merge upstream/main with your code. For a step-by-step guide to resolve merge conflicts, see https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/addressing-merge-conflicts/resolving-a-merge-conflict-using-the-command-line.

@@ -481,7 +481,15 @@ public static String getFieldValue(BibEntry entry, String pattern, Character key
} else if (pattern.matches("keyword\\d+")) {
// according to LabelPattern.php, it returns keyword number n
int num = Integer.parseInt(pattern.substring(7));
KeywordList separatedKeywords = entry.getResolvedKeywords(keywordDelimiter, database);
// KeywordList separatedKeywords = entry.getResolvedKeywords(keywordDelimiter, database);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented code should be removed as it serves no purpose in understanding the current implementation and clutters the codebase. Git history should be used to track changes.

@@ -481,7 +481,15 @@ public static String getFieldValue(BibEntry entry, String pattern, Character key
} else if (pattern.matches("keyword\\d+")) {
// according to LabelPattern.php, it returns keyword number n
int num = Integer.parseInt(pattern.substring(7));
KeywordList separatedKeywords = entry.getResolvedKeywords(keywordDelimiter, database);
// KeywordList separatedKeywords = entry.getResolvedKeywords(keywordDelimiter, database);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another instance of commented code that should be removed. Version control systems like Git are designed to maintain code history, making commented-out code unnecessary.

@calixtus
Copy link
Member

Thanks for your interest in jabref.
I believe just replacing character with string is the wrong approach. This may work on a from a simple programming perspective. But you need arcane knowledge to deal with that string. One must know that every character in the string is a delimiter.

If you want to push around a list of multiple delimiters, use a list. Keep the level of abstraction. Maybe one wants du use "./." As a delimiter?

Also please add tests / use test driven development as @koppor suggests.
Create test cases, create tests, see them fail, fix the codebase.

@tushar-2320
Copy link
Contributor Author

Thanks for your interest in jabref. I believe just replacing character with string is the wrong approach. This may work on a from a simple programming perspective. But you need arcane knowledge to deal with that string. One must know that every character in the string is a delimiter.

If you want to push around a list of multiple delimiters, use a list. Keep the level of abstraction. Maybe one wants du use "./." As a delimiter?

Also please add tests / use test driven development as @koppor suggests. Create test cases, create tests, see them fail, fix the codebase.

actually I am facing difficulty in that .
I dont know in which test file I need to write the test case can you give me a particular file name @calixtus ?

@calixtus
Copy link
Member

KeywordListTest.java

@koppor
Copy link
Member

koppor commented Aug 31, 2025

KeywordListTest.java

First, I was not sure if this OK - however, the KeywordList can have different parsing modes. Maybe with a heuristics to find out the keyword seperator - then this list can be serialized again and put into the BibEntry returned by the fetcher.

@jabref-machine
Copy link
Collaborator

Note that your PR will not be reviewed/accepted until you have gone through the mandatory checks in the description and marked each of them them exactly in the format of [x] (done), [ ] (not done yet) or [/] (not applicable).

@@ -73,6 +94,10 @@ public static KeywordList parse(String keywordString, Character delimiter) {
return parse(keywordString, delimiter, Keyword.DEFAULT_HIERARCHICAL_DELIMITER);
}

public static KeywordList parseMultipleDelimeter(String keywordString, String delimiter) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method name contains a spelling error ('Delimeter' instead of 'Delimiter'), which violates consistent and correct naming conventions in the codebase.

Comment on lines +74 to +76
for (char d:delimiter.toCharArray()) {
keywordString = keywordString.replace(d, ',');
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String mutation in loop is inefficient. Using StringBuilder or StringJoiner would be more performant for string manipulations.

@Test
void parseMultipleDelimiter() {
assertEquals(new KeywordList("keywordOne", "keywordTwo", "keywordThree"),
KeywordList.parseMultipleDelimeter("keywordOne; keywordTwo: keywordThree", ";:"));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method name contains a typo ('Delimeter' instead of 'Delimiter'), which violates the requirement for correctly spelled variable and method names.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Treat ";" as keyword separator when importing bibtex data or replace them with ","
5 participants