Skip to content

fix for 9699. Added bimap for language-lcid mapping#9729

Merged
Siedlerchr merged 9 commits into
JabRef:mainfrom
yenniejunvu:fix-for-9699
Apr 15, 2023
Merged

fix for 9699. Added bimap for language-lcid mapping#9729
Siedlerchr merged 9 commits into
JabRef:mainfrom
yenniejunvu:fix-for-9699

Conversation

@yenniejunvu

@yenniejunvu yenniejunvu commented Apr 2, 2023

Copy link
Copy Markdown
Contributor

Fixes #9699

Added a private static bimap for supporting more lcids/languages when exporting to MS Office 2007.
Added simple unit tests, but not sure if those are necessary.

### Compulsory checks
- [x ] Change in `CHANGELOG.md` described in a way that is understandable for the average user (if applicable)
- [ ] Tests created for changes (if applicable)
- [ ] Manually tested changed features in running JabRef (always required)
- [ ] Screenshots added in PR description (for UI changes)
- [ x] [Checked developer's documentation](https://devdocs.jabref.org/): Is the information available and up to date? If not, I outlined it in this pull request.
- [ x] [Checked documentation](https://docs.jabref.org/): 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.

@koppor koppor left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good initial shot.

MSBibConverter.java also should be adapted.

Please add test for MsBibConverter using Ctrl+Shift+T

image

Press then Enter

Then create a test case with a BibEntry.

See IEEETest.java for a more complete example.


private static final HashBiMap<Field, String> BIBLATEX_TO_MS_BIB = HashBiMap.create();

private static final HashBiMap<String, Integer> LANG_TO_LCID = HashBiMap.create();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you really need HashBiMap here? Isn't BiMap enough?

See https://github.com/HugoMatilla/Effective-JAVA-Summary#52-refer-to-objects-by-their-interface for a longer explanation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Doesnt the same logic apply for BIBLATEX_TO_MS_BIB as well?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think so.

@@ -131,8 +170,8 @@ public static MSBibEntryType getMSBibEntryType(EntryType bibtexType) {
*/
public static int getLCID(String language) {
// TODO: add language to LCID mapping

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This TODO can be removed.

Also fix the checkstyle issue!

@koppor

koppor commented Apr 3, 2023

Copy link
Copy Markdown
Member

See also that the tests start to fail: Please check the tests:

image

@yenniejunvu

Copy link
Copy Markdown
Contributor Author

My bad about the unit tests. I'll take a look and make some fixes. Thanks for the quick feedback.

@yenniejunvu

Copy link
Copy Markdown
Contributor Author

@return Returns 0 for English

In regards to the unit tests failing,
I saw this comment above the getLCID function while trying to fix the issue, and noticed that if I set the LCID to '0' in the BiMap for english, the tests pass fine. However, according to documentation,
"Word sets LCID to 0 to mean the value should be determined at runtime by the application." (https://learn.microsoft.com/en-us/openspecs/office_standards/ms-oe376/6c085406-a698-4e12-9d4d-c3b0ee3dbc4a)

Not quite sure what to do here.

Additionally, since @Alexandra-Stath was assigned to this problem first, you do not need to review this PR until she submits a PR as well or says it is okay. I just do not want this to get merged, since she was technically assigned it first as a course project!

@koppor koppor removed the status: changes-required Pull requests that are not yet complete label Apr 5, 2023
@koppor koppor marked this pull request as draft April 5, 2023 05:28
@koppor

koppor commented Apr 7, 2023

Copy link
Copy Markdown
Member

Without thinking much, my question would be, why can't 0 be kept?`

Are all these null pointer exceptions really because of this?

@Siedlerchr

Copy link
Copy Markdown
Member

I think the tests are failing because the xml files for the tests probably contain 0 for the language. And there is no map entry with 0 inside. So either add an entry for 0 or do something like getOrDefault

Comment thread src/test/java/org/jabref/logic/msbib/MsBibMappingTest.java
@yenniejunvu

Copy link
Copy Markdown
Contributor Author

@Siedlerchr I'm not sure if that's the case, because the previous implementation of getLCID() returned the hexidecimal value of 1033, which is the LCID for american english.

@koppor

koppor commented Apr 10, 2023

Copy link
Copy Markdown
Member

@Siedlerchr I'm not sure if that's the case, because the previous implementation of getLCID() returned the hexidecimal value of 1033, which is the LCID for american english.

This is good!

Without thinking deeper about the consequences, just fallback to 1033 if there is no mapping in the map?

(And please adapt the wrong comment @return Returns 0 for English if not already done so)

@Siedlerchr

Copy link
Copy Markdown
Member

@yenniejunvu

yenniejunvu commented Apr 10, 2023

Copy link
Copy Markdown
Contributor Author

I added MSBibConverterTest but I am not sure if that is what you guys are expecting.
Additionally, I added some error handling. If there is an invalid language/lcid passed, it all defaults to english.

(my last commit had some missing files, which is why the unit tests were failing :,( )

if (!LANG_TO_LCID.containsKey(language)) {
return 1033;
}
return LANG_TO_LCID.get(language);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

You can use getOrDefault

@yenniejunvu

Copy link
Copy Markdown
Contributor Author

Not sure why that one test is now suddenly failing, it works fine on my local machine...

Comment thread src/main/java/org/jabref/logic/msbib/MSBibMapping.java
@Siedlerchr

Copy link
Copy Markdown
Member

The test sometimes fails randomly on CI. Don't worry. If you think your PR is ready then you can mark it as ready for review. In my opinion it looks good now

@Siedlerchr Siedlerchr added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Apr 13, 2023
Siedlerchr
Siedlerchr previously approved these changes Apr 13, 2023
@yenniejunvu yenniejunvu marked this pull request as ready for review April 13, 2023 18:28
Add import as well
@Siedlerchr Siedlerchr merged commit 62e3d3f into JabRef:main Apr 15, 2023
Comment thread CHANGELOG.md
- We improved the Drag and Drop behavior in the "Customize Entry Types" Dialog [#6338](https://github.com/JabRef/jabref/issues/6338)
- When determining the URL of an ArXiV eprint, the URL now points to the version [#8149](https://github.com/JabRef/jabref/pull/8149)
- We Included all standard fields with citation key when exporting to Old OpenOffice/LibreOffice Calc Format [#8176](https://github.com/JabRef/jabref/pull/8176)
- We Included all standard fields with citation key when exporting to Old OpenOffice/LibreExpoa Calc Format [#8176](https://github.com/JabRef/jabref/pull/8176)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@Siedlerchr What is "LibreExpoa"? Is this change in CHANGELOG.md really intended?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I was editing this on the github, this was not intended

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Fixed it directly in main at 461e915

@koppor koppor mentioned this pull request Mar 17, 2024
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Export Office 2007 bibliography source with LCID

5 participants