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);
}
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());
}
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;
}
Aggregations