Search in sources :

Example 1 with RegexKeywordGroup

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

the class GroupSerializerTest method serializeSingleRegexKeywordGroup.

@Test
public void serializeSingleRegexKeywordGroup() {
    KeywordGroup group = new RegexKeywordGroup("myExplicitGroup", GroupHierarchyType.REFINING, "author", "asdf", false);
    List<String> serialization = groupSerializer.serializeTree(GroupTreeNode.fromGroup(group));
    assertEquals(Collections.singletonList("0 KeywordGroup:myExplicitGroup;1;author;asdf;0;1;1;;;;"), serialization);
}
Also used : AutomaticKeywordGroup(org.jabref.model.groups.AutomaticKeywordGroup) KeywordGroup(org.jabref.model.groups.KeywordGroup) RegexKeywordGroup(org.jabref.model.groups.RegexKeywordGroup) WordKeywordGroup(org.jabref.model.groups.WordKeywordGroup) RegexKeywordGroup(org.jabref.model.groups.RegexKeywordGroup) GroupTreeNodeTest(org.jabref.model.groups.GroupTreeNodeTest) Test(org.junit.Test)

Example 2 with RegexKeywordGroup

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

the class BibtexParserTest method integrationTestGroupTree.

@Test
public void integrationTestGroupTree() throws IOException, ParseException {
    ParserResult result = BibtexParser.parse(new StringReader("@comment{jabref-meta: groupsversion:3;}" + OS.NEWLINE + "@comment{jabref-meta: groupstree:" + OS.NEWLINE + "0 AllEntriesGroup:;" + OS.NEWLINE + "1 KeywordGroup:Fréchet\\;0\\;keywords\\;FrechetSpace\\;0\\;1\\;;" + OS.NEWLINE + "1 KeywordGroup:Invariant theory\\;0\\;keywords\\;GIT\\;0\\;0\\;;" + OS.NEWLINE + "1 ExplicitGroup:TestGroup\\;0\\;Key1\\;Key2\\;;" + "}"), importFormatPreferences);
    GroupTreeNode root = result.getMetaData().getGroups().get();
    assertEquals(new AllEntriesGroup("All entries"), root.getGroup());
    assertEquals(3, root.getNumberOfChildren());
    assertEquals(new RegexKeywordGroup("Fréchet", GroupHierarchyType.INDEPENDENT, "keywords", "FrechetSpace", false), root.getChildren().get(0).getGroup());
    assertEquals(new WordKeywordGroup("Invariant theory", GroupHierarchyType.INDEPENDENT, "keywords", "GIT", false, ',', false), root.getChildren().get(1).getGroup());
    assertEquals(Arrays.asList("Key1", "Key2"), ((ExplicitGroup) root.getChildren().get(2).getGroup()).getLegacyEntryKeys());
}
Also used : AllEntriesGroup(org.jabref.model.groups.AllEntriesGroup) ParserResult(org.jabref.logic.importer.ParserResult) StringReader(java.io.StringReader) GroupTreeNode(org.jabref.model.groups.GroupTreeNode) RegexKeywordGroup(org.jabref.model.groups.RegexKeywordGroup) WordKeywordGroup(org.jabref.model.groups.WordKeywordGroup) Test(org.junit.Test)

Example 3 with RegexKeywordGroup

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

the class GroupsParser method keywordGroupFromString.

/**
     * Parses s and recreates the KeywordGroup from it.
     *
     * @param s The String representation obtained from
     *          KeywordGroup.toString()
     */
private static KeywordGroup keywordGroupFromString(String s, Character keywordSeparator) throws ParseException {
    if (!s.startsWith(MetadataSerializationConfiguration.KEYWORD_GROUP_ID)) {
        throw new IllegalArgumentException("KeywordGroup cannot be created from \"" + s + "\".");
    }
    QuotedStringTokenizer tok = new QuotedStringTokenizer(s.substring(MetadataSerializationConfiguration.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);
    String expression = StringUtil.unquote(tok.nextToken(), MetadataSerializationConfiguration.GROUP_QUOTE_CHAR);
    boolean caseSensitive = Integer.parseInt(tok.nextToken()) == 1;
    boolean regExp = Integer.parseInt(tok.nextToken()) == 1;
    KeywordGroup newGroup;
    if (regExp) {
        newGroup = new RegexKeywordGroup(name, context, field, expression, caseSensitive);
    } else {
        newGroup = new WordKeywordGroup(name, context, field, expression, caseSensitive, keywordSeparator, false);
    }
    addGroupDetails(tok, newGroup);
    return newGroup;
}
Also used : AutomaticKeywordGroup(org.jabref.model.groups.AutomaticKeywordGroup) KeywordGroup(org.jabref.model.groups.KeywordGroup) RegexKeywordGroup(org.jabref.model.groups.RegexKeywordGroup) WordKeywordGroup(org.jabref.model.groups.WordKeywordGroup) QuotedStringTokenizer(org.jabref.logic.util.strings.QuotedStringTokenizer) GroupHierarchyType(org.jabref.model.groups.GroupHierarchyType) RegexKeywordGroup(org.jabref.model.groups.RegexKeywordGroup) WordKeywordGroup(org.jabref.model.groups.WordKeywordGroup)

Aggregations

RegexKeywordGroup (org.jabref.model.groups.RegexKeywordGroup)3 WordKeywordGroup (org.jabref.model.groups.WordKeywordGroup)3 AutomaticKeywordGroup (org.jabref.model.groups.AutomaticKeywordGroup)2 KeywordGroup (org.jabref.model.groups.KeywordGroup)2 Test (org.junit.Test)2 StringReader (java.io.StringReader)1 ParserResult (org.jabref.logic.importer.ParserResult)1 QuotedStringTokenizer (org.jabref.logic.util.strings.QuotedStringTokenizer)1 AllEntriesGroup (org.jabref.model.groups.AllEntriesGroup)1 GroupHierarchyType (org.jabref.model.groups.GroupHierarchyType)1 GroupTreeNode (org.jabref.model.groups.GroupTreeNode)1 GroupTreeNodeTest (org.jabref.model.groups.GroupTreeNodeTest)1