Search in sources :

Example 1 with AutomaticKeywordGroup

use of org.jabref.model.groups.AutomaticKeywordGroup in project jabref by JabRef.

the class GroupNodeViewModelTest method treeOfAutomaticKeywordGroupIsCombined.

@Test
public void treeOfAutomaticKeywordGroupIsCombined() throws Exception {
    BibEntry entryOne = new BibEntry().withField("keywords", "A > B > B1, A > C");
    BibEntry entryTwo = new BibEntry().withField("keywords", "A > D, E");
    BibEntry entryThree = new BibEntry().withField("keywords", "A > B > B2");
    databaseContext.getDatabase().insertEntries(entryOne, entryTwo, entryThree);
    AutomaticKeywordGroup group = new AutomaticKeywordGroup("Keywords", GroupHierarchyType.INDEPENDENT, "keywords", ',', '>');
    GroupNodeViewModel groupViewModel = getViewModelForGroup(group);
    WordKeywordGroup expectedGroupA = new WordKeywordGroup("A", GroupHierarchyType.INCLUDING, "keywords", "A", true, ',', true);
    WordKeywordGroup expectedGroupB = new WordKeywordGroup("B", GroupHierarchyType.INCLUDING, "keywords", "A > B", true, ',', true);
    WordKeywordGroup expectedGroupB1 = new WordKeywordGroup("B1", GroupHierarchyType.INCLUDING, "keywords", "A > B > B1", true, ',', true);
    WordKeywordGroup expectedGroupB2 = new WordKeywordGroup("B2", GroupHierarchyType.INCLUDING, "keywords", "A > B > B2", true, ',', true);
    WordKeywordGroup expectedGroupC = new WordKeywordGroup("C", GroupHierarchyType.INCLUDING, "keywords", "A > C", true, ',', true);
    WordKeywordGroup expectedGroupD = new WordKeywordGroup("D", GroupHierarchyType.INCLUDING, "keywords", "A > D", true, ',', true);
    WordKeywordGroup expectedGroupE = new WordKeywordGroup("E", GroupHierarchyType.INCLUDING, "keywords", "E", true, ',', true);
    GroupNodeViewModel expectedA = getViewModelForGroup(expectedGroupA);
    GroupTreeNode expectedB = expectedA.addSubgroup(expectedGroupB);
    expectedB.addSubgroup(expectedGroupB1);
    expectedB.addSubgroup(expectedGroupB2);
    expectedA.addSubgroup(expectedGroupC);
    expectedA.addSubgroup(expectedGroupD);
    GroupNodeViewModel expectedE = getViewModelForGroup(expectedGroupE);
    ObservableList<GroupNodeViewModel> expected = FXCollections.observableArrayList(expectedA, expectedE);
    assertEquals(expected, groupViewModel.getChildren());
}
Also used : BibEntry(org.jabref.model.entry.BibEntry) AutomaticKeywordGroup(org.jabref.model.groups.AutomaticKeywordGroup) GroupTreeNode(org.jabref.model.groups.GroupTreeNode) WordKeywordGroup(org.jabref.model.groups.WordKeywordGroup) Test(org.junit.Test)

Example 2 with AutomaticKeywordGroup

use of org.jabref.model.groups.AutomaticKeywordGroup in project jabref by JabRef.

the class GroupSerializerTest method serializeSingleAutomaticKeywordGroup.

@Test
public void serializeSingleAutomaticKeywordGroup() {
    AutomaticGroup group = new AutomaticKeywordGroup("myAutomaticGroup", GroupHierarchyType.INDEPENDENT, "keywords", ',', '>');
    List<String> serialization = groupSerializer.serializeTree(GroupTreeNode.fromGroup(group));
    assertEquals(Collections.singletonList("0 AutomaticKeywordGroup:myAutomaticGroup;0;keywords;,;>;1;;;;"), serialization);
}
Also used : AutomaticKeywordGroup(org.jabref.model.groups.AutomaticKeywordGroup) AutomaticGroup(org.jabref.model.groups.AutomaticGroup) GroupTreeNodeTest(org.jabref.model.groups.GroupTreeNodeTest) Test(org.junit.Test)

Example 3 with AutomaticKeywordGroup

use of org.jabref.model.groups.AutomaticKeywordGroup in project jabref by JabRef.

the class GroupsParserTest method fromStringParsesAutomaticKeywordGroup.

@Test
public void fromStringParsesAutomaticKeywordGroup() throws Exception {
    AutomaticGroup expected = new AutomaticKeywordGroup("myAutomaticGroup", GroupHierarchyType.INDEPENDENT, "keywords", ',', '>');
    AbstractGroup parsed = GroupsParser.fromString("AutomaticKeywordGroup:myAutomaticGroup;0;keywords;,;>;1;;;;", ',');
    assertEquals(expected, parsed);
}
Also used : AutomaticKeywordGroup(org.jabref.model.groups.AutomaticKeywordGroup) AbstractGroup(org.jabref.model.groups.AbstractGroup) AutomaticGroup(org.jabref.model.groups.AutomaticGroup) Test(org.junit.Test)

Example 4 with AutomaticKeywordGroup

use of org.jabref.model.groups.AutomaticKeywordGroup in project jabref by JabRef.

the class GroupsParser method automaticKeywordGroupFromString.

private static AbstractGroup automaticKeywordGroupFromString(String string) {
    if (!string.startsWith(MetadataSerializationConfiguration.AUTOMATIC_KEYWORD_GROUP_ID)) {
        throw new IllegalArgumentException("KeywordGroup cannot be created from \"" + string + "\".");
    }
    QuotedStringTokenizer tok = new QuotedStringTokenizer(string.substring(MetadataSerializationConfiguration.AUTOMATIC_KEYWORD_GROUP_ID.length()), MetadataSerializationConfiguration.GROUP_UNIT_SEPARATOR, MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    String name = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    GroupHierarchyType context = GroupHierarchyType.getByNumberOrDefault(Integer.parseInt(tok.nextToken()));
    String field = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    Character delimiter = tok.nextToken().charAt(0);
    Character hierarchicalDelimiter = tok.nextToken().charAt(0);
    AutomaticKeywordGroup newGroup = new AutomaticKeywordGroup(name, context, field, delimiter, hierarchicalDelimiter);
    addGroupDetails(tok, newGroup);
    return newGroup;
}
Also used : AutomaticKeywordGroup(org.jabref.model.groups.AutomaticKeywordGroup) QuotedStringTokenizer(org.jabref.logic.util.strings.QuotedStringTokenizer) GroupHierarchyType(org.jabref.model.groups.GroupHierarchyType)

Aggregations

AutomaticKeywordGroup (org.jabref.model.groups.AutomaticKeywordGroup)4 Test (org.junit.Test)3 AutomaticGroup (org.jabref.model.groups.AutomaticGroup)2 QuotedStringTokenizer (org.jabref.logic.util.strings.QuotedStringTokenizer)1 BibEntry (org.jabref.model.entry.BibEntry)1 AbstractGroup (org.jabref.model.groups.AbstractGroup)1 GroupHierarchyType (org.jabref.model.groups.GroupHierarchyType)1 GroupTreeNode (org.jabref.model.groups.GroupTreeNode)1 GroupTreeNodeTest (org.jabref.model.groups.GroupTreeNodeTest)1 WordKeywordGroup (org.jabref.model.groups.WordKeywordGroup)1