Skip to content
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

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

Merged
merged 9 commits into from
Apr 15, 2023

Conversation

yenniejunvu
Copy link
Contributor

@yenniejunvu yenniejunvu commented Apr 2, 2023

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.

Tasks

Preview Give feedback

Copy link
Member

@koppor koppor left a comment

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.

@@ -24,6 +24,45 @@ public class MSBibMapping {

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
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
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
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
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
Copy link
Member

koppor commented Apr 3, 2023

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

image

@yenniejunvu
Copy link
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
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
Copy link
Member

koppor commented Apr 7, 2023

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
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

@yenniejunvu
Copy link
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
Copy link
Member

koppor commented Apr 10, 2023

@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)

@yenniejunvu
Copy link
Contributor Author

yenniejunvu commented Apr 10, 2023

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 :,( )

*/
public static int getLCID(String language) {
if (!LANG_TO_LCID.containsKey(language)) {
return 1033;
}
return LANG_TO_LCID.get(language);
Copy link
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
Contributor Author

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

@Siedlerchr
Copy link
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
@@ -381,7 +381,7 @@ Note that this project **does not** adhere to [Semantic Versioning](http://semve
- We moved the union/intersection view button in the group sidepane to the left of the other controls. [#8202](https://github.com/JabRef/jabref/pull/8202)
- 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
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
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
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