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

Automatically created groups with Field to group by as entrytype (#4539) #4555

Merged
merged 4 commits into from
Feb 9, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `#
- We updated updated the Related Articles tab to accept JSON from the new version of the Mr. DLib service
- We added an option in the preference dialog box that allows user to choose behavior after dragging and dropping files in Entry Editor. [#4356](https://github.com/JabRef/jabref/issues/4356)
- We added the ability to have an export preference where previously "File"-->"Export"/"Export selected entries" would not save the user's preference[#4495](https://github.com/JabRef/jabref/issues/4495)

- For automatically created groups, added ability to filter groups by entry type. [#4539](https://github.com/JabRef/jabref/issues/4539)



Expand Down
11 changes: 10 additions & 1 deletion src/main/java/org/jabref/model/entry/BibEntry.java
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ private void invalidateFieldCache(String fieldName) {
}

public Optional<String> getLatexFreeField(String name) {
if (!hasField(name)) {
if (!hasField(name) && !TYPE_HEADER.equals(name)) {
return Optional.empty();
} else if (latexFreeFields.containsKey(name)) {
return Optional.ofNullable(latexFreeFields.get(toLowerCase(name)));
Expand All @@ -812,6 +812,15 @@ public Optional<String> getLatexFreeField(String name) {
Optional<String> citeKey = getCiteKeyOptional();
latexFreeFields.put(name, citeKey.get());
return citeKey;
} else if (TYPE_HEADER.equals(name)) {
Optional<EntryType> entryType = EntryTypes.getType(getType(), BibDatabaseMode.BIBLATEX);
if (entryType.isPresent()) {
String entryName = entryType.get().getName();
latexFreeFields.put(name, entryName);
return Optional.of(entryName);
} else {
return Optional.of(StringUtil.capitalizeFirst(getType()));
}
} else {
String latexFreeField = LatexToUnicodeAdapter.format(getField(name).get()).intern();
latexFreeFields.put(name, latexFreeField);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/org/jabref/model/groups/WordKeywordGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import org.jabref.model.EntryTypes;
import org.jabref.model.FieldChange;
import org.jabref.model.database.BibDatabaseMode;
import org.jabref.model.entry.BibEntry;
import org.jabref.model.entry.EntryType;
import org.jabref.model.entry.KeywordList;
import org.jabref.model.strings.StringUtil;

Expand Down Expand Up @@ -113,6 +118,12 @@ public boolean contains(BibEntry entry) {

private Set<String> getFieldContentAsWords(BibEntry entry) {
if (onlySplitWordsAtSeparator) {
if (BibEntry.TYPE_HEADER.equals(searchField)) {
Optional<EntryType> entryType = EntryTypes.getType(entry.getType(), BibDatabaseMode.BIBLATEX);
if (entryType.isPresent()) {
Copy link
Member

Choose a reason for hiding this comment

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

As above, entryType = EntryTypes.getType(entry.getType(), BibDatabaseMode.BIBLATEX).orElse(entry.getType()) is slightly better.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Type mismatch occurs. entry.getType() is String while we are assigning value for Optional<EntryType> here

return searchWords.stream().filter(sw -> entryType.get().getName().equals(sw)).collect(Collectors.toSet());
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason for filtering the searchWords list? I think you can safely return the value of entryType (as a 1-item list).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

searchWords is a 1-item set. Filter method lets me compare the content of this set with the entry type. Example, searchWord can be 'Book' but the entry type can be 'Article' and hence, this entry won't fall under Book subgroup. Other approach that I could think of -

if (entryType.isPresent() && searchWords.iterator().next().equals(entryType.get().getName())) {
return searchWords;
}

Please suggest.

Copy link
Member

Choose a reason for hiding this comment

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

Your solution sounds reasoable, I would let it as is.

}
}
return entry.getField(searchField)
.map(content -> KeywordList.parse(content, keywordSeparator).toStringList())
.orElse(Collections.emptySet());
Expand Down