Cleanup for version 0.2
Change-Id: I383ed12da8abc96b233c0694612f837b49731201
diff --git a/.classpath b/.classpath
deleted file mode 100644
index 9c865fb..0000000
--- a/.classpath
+++ /dev/null
@@ -1,26 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" output="target/classes" path="src/main/java">
- <attributes>
- <attribute name="optional" value="true"/>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="src" output="target/test-classes" path="src/test/java">
- <attributes>
- <attribute name="optional" value="true"/>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
- <attributes>
- <attribute name="maven.pomderived" value="true"/>
- </attributes>
- </classpathentry>
- <classpathentry kind="output" path="target/classes"/>
-</classpath>
diff --git a/.project b/.project
deleted file mode 100644
index 53c51ae..0000000
--- a/.project
+++ /dev/null
@@ -1,23 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>Koral</name>
- <comment></comment>
- <projects>
- </projects>
- <buildSpec>
- <buildCommand>
- <name>org.eclipse.jdt.core.javabuilder</name>
- <arguments>
- </arguments>
- </buildCommand>
- <buildCommand>
- <name>org.eclipse.m2e.core.maven2Builder</name>
- <arguments>
- </arguments>
- </buildCommand>
- </buildSpec>
- <natures>
- <nature>org.eclipse.jdt.core.javanature</nature>
- <nature>org.eclipse.m2e.core.maven2Nature</nature>
- </natures>
-</projectDescription>
diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index ec4300d..0000000
--- a/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,5 +0,0 @@
-eclipse.preferences.version=1
-org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7
-org.eclipse.jdt.core.compiler.compliance=1.7
-org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
-org.eclipse.jdt.core.compiler.source=1.7
diff --git a/Changes b/Changes
new file mode 100644
index 0000000..d3afe61
--- /dev/null
+++ b/Changes
@@ -0,0 +1,7 @@
+0.2 2015-06-15
+ - Switch to "koral:" prefix.
+ - Coverage of KoralQuery 0.3
+ (see http://korap.github.io/Koral/)
+
+0.1 2015-02-10
+ - First version published to GitHub.
diff --git a/Format.xml b/Format.xml
new file mode 100644
index 0000000..7c749b0
--- /dev/null
+++ b/Format.xml
@@ -0,0 +1,291 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<profiles version="12">
+<profile kind="CodeFormatterProfile" name="korap" version="12">
+<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.disabling_tag" value="@formatter:off"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_block_boundaries" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_field" value="0"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.use_on_off_tags" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_ellipsis" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_multiple_fields" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_conditional_expression" value="80"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_binary_operator" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_array_initializer" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_package" value="1"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.continuation_indentation" value="2"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk" value="1"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_binary_operator" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_package" value="0"/>
+<setting id="org.eclipse.jdt.core.compiler.source" value="1.7"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.format_line_comments" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.join_wrapped_lines" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_member_type" value="1"/>
+<setting id="org.eclipse.jdt.core.formatter.align_type_members_on_columns" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_unary_operator" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.indent_parameter_description" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.lineSplit" value="80"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration" value="0"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_method" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.indentation.size" value="4"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.enabling_tag" value="@formatter:on"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_assignment" value="0"/>
+<setting id="org.eclipse.jdt.core.compiler.problem.assertIdentifier" value="error"/>
+<setting id="org.eclipse.jdt.core.formatter.tabulation.char" value="space"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_try_resources" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_body" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_method" value="2"/>
+<setting id="org.eclipse.jdt.core.formatter.wrap_outer_expressions_when_nested" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration" value="18"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_method_declaration" value="0"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_try" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_switch" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_try" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.preserve_white_space_between_code_and_line_comments" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.compiler.problem.enumIdentifier" value="error"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_ellipsis" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_method_declaration" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.compact_else_if" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.wrap_before_or_operator_multicatch" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.format_line_comment_starting_on_first_column" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.indent_root_tags" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_constant" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_union_type_in_multicatch" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.tabulation.size" value="4"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_empty_lines" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_block_in_case" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve" value="3"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter" value="insert"/>
+<setting id="org.eclipse.jdt.core.compiler.compliance" value="1.7"/>
+<setting id="org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer" value="2"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_unary_operator" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_binary_expression" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_type" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode" value="enabled"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_try" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_label" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.format_javadoc_comments" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.line_length" value="70"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_package" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_import_groups" value="1"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body" value="0"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.wrap_before_binary_operator" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations" value="1"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_statements_compare_to_block" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.join_lines_in_comments" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_compact_if" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_before_imports" value="1"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.format_html" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.format_source_code" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration" value="16"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer" value="insert"/>
+<setting id="org.eclipse.jdt.core.compiler.codegen.targetPlatform" value="1.7"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_resources_in_try" value="80"/>
+<setting id="org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_arguments_in_annotation" value="0"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.format_header" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.format_block_comments" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.alignment_for_enum_constants" value="0"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.brace_position_for_type_declaration" value="end_of_line"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.comment.new_lines_at_javadoc_boundaries" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.blank_lines_after_imports" value="1"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header" value="true"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for" value="insert"/>
+<setting id="org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_try_resources" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments" value="do not insert"/>
+<setting id="org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column" value="false"/>
+<setting id="org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line" value="false"/>
+</profile>
+</profiles>
diff --git a/README.md b/README.md
index a26ab9e..788241c 100644
--- a/README.md
+++ b/README.md
@@ -1,4 +1,4 @@
-# Koral v0.1
+# Koral
Koral is a library designed for the translation of different corpus query
languages to KoralQuery, a JSON-LD-based protocol for the common representation
@@ -37,44 +37,44 @@
```json
{
- "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.2/context.jsonld",
- "query": {
+ "@context": "http://korap.ids-mannheim.de/ns/KoralQuery/v0.2/context.jsonld",
+ "query": {
+ "@type": "koral:group",
+ "operation": "operation:position",
+ "frames": [
+ "frames:isAround"
+ ],
+ "operands": [
+ {
+ "@type": "koral:span",
+ "key": "s"
+ },
+ {
"@type": "koral:group",
- "operation": "operation:position",
- "frames": [
- "frames:isAround"
- ],
+ "operation": "operation:sequence",
"operands": [
- {
- "@type": "koral:span",
- "key": "s"
- },
- {
- "@type": "koral:group",
- "operation": "operation:sequence",
- "operands": [
- {
- "@type": "koral:token",
- "wrap": {
- "@type": "koral:term",
- "layer": "orth",
- "key": "zu",
- "match": "match:eq"
- }
- },
- {
- "@type": "koral:token",
- "wrap": {
- "@type": "koral:term",
- "layer": "pos",
- "key": "ADJA",
- "match": "match:eq"
- }
- }
- ]
+ {
+ "@type": "koral:token",
+ "wrap": {
+ "@type": "koral:term",
+ "layer": "orth",
+ "key": "zu",
+ "match": "match:eq"
}
+ },
+ {
+ "@type": "koral:token",
+ "wrap": {
+ "@type": "koral:term",
+ "layer": "pos",
+ "key": "ADJA",
+ "match": "match:eq"
+ }
+ }
]
- }
+ }
+ ]
+ }
}
```
@@ -102,7 +102,7 @@
There is also a command line version. After installation, simply run
- java -jar target/Koral-0.1.jar [query] [queryLanguage]
+ java -jar target/Koral-0.2.jar [query] [queryLanguage]
## Authorship
diff --git a/pom.xml b/pom.xml
index f858cbc..27de904 100644
--- a/pom.xml
+++ b/pom.xml
@@ -1,226 +1,224 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
- <!-- <parent> <groupId>KorAP-modules</groupId> <artifactId>KorAP-core-modules</artifactId>
- <version>1.1</version> </parent> -->
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <!-- <parent> <groupId>KorAP-modules</groupId> <artifactId>KorAP-core-modules</artifactId>
+ <version>1.1</version> </parent> -->
- <groupId>KorAP-modules</groupId>
- <artifactId>Koral</artifactId>
- <version>0.1</version>
- <packaging>jar</packaging>
- <name>Koral</name>
- <url>http://maven.apache.org</url>
- <repositories>
- <repository>
- <id>id-maven-repo</id>
- <url>http://maven.indexdata.com</url>
- </repository>
- </repositories>
- <dependencies>
- <dependency>
- <groupId>org.antlr</groupId>
- <artifactId>antlr4-runtime</artifactId>
- <version>4.1</version>
- </dependency>
- <dependency>
- <groupId>org.antlr</groupId>
- <artifactId>antlr4-maven-plugin</artifactId>
- <version>4.1</version>
- </dependency>
- <dependency>
- <groupId>org.antlr</groupId>
- <artifactId>antlr-runtime</artifactId>
- <version>3.5</version>
- <scope>compile</scope>
- </dependency>
- <dependency>
- <groupId>com.google.guava</groupId>
- <artifactId>guava</artifactId>
- <version>15.0</version>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-core</artifactId>
- <version>2.3.3</version>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-annotations</artifactId>
- <version>2.3.3</version>
- </dependency>
- <dependency>
- <groupId>com.fasterxml.jackson.core</groupId>
- <artifactId>jackson-databind</artifactId>
- <version>2.3.3</version>
- </dependency>
- <!-- dependency> <groupId>KorAP-modules</groupId> <artifactId>KorAP-PoliqarpParser</artifactId>
- <version>0.1</version> </dependency> <dependency> <groupId>KorAP-modules</groupId>
- <artifactId>KorAP-Cosmas2Parser</artifactId> <version>0.02</version> </dependency>
- <dependency> <groupId>KorAP-modules</groupId> <artifactId>KorAP-AnnisParser</artifactId>
- <version>0.01</version> </dependency -->
- <dependency>
- <groupId>junit</groupId>
- <artifactId>junit</artifactId>
- <version>4.11</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>commons-lang</groupId>
- <artifactId>commons-lang</artifactId>
- <version>2.6</version>
- </dependency>
- <dependency>
- <groupId>org.z3950.zing</groupId>
- <artifactId>cql-java</artifactId>
- <version>1.12</version>
- </dependency>
- <dependency>
- <groupId>org.projectlombok</groupId>
- <artifactId>lombok</artifactId>
- <version>0.11.8</version>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>log4j</artifactId>
- <version>1.2.17</version>
- </dependency>
- <dependency>
- <groupId>log4j</groupId>
- <artifactId>apache-log4j-extras</artifactId>
- <version>1.2.17</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-api</artifactId>
- <version>1.7.5</version>
- </dependency>
- <dependency>
- <groupId>org.slf4j</groupId>
- <artifactId>slf4j-log4j12</artifactId>
- <version>1.7.5</version>
- </dependency>
- </dependencies>
- <build>
- <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
- <outputDirectory>${basedir}/target/classes</outputDirectory>
- <plugins>
- <!-- Formatter plugin for Eclipse based coding conventions http://maven-java-formatter-plugin.googlecode.com/svn/site/0.4/usage.html -->
- <plugin>
- <groupId>com.googlecode.maven-java-formatter-plugin</groupId>
- <artifactId>maven-java-formatter-plugin</artifactId>
- <version>0.4</version>
- <configuration>
- <configFile>${project.basedir}/korap-style.xml</configFile>
- <overrideConfigCompilerVersion>true</overrideConfigCompilerVersion>
- <compilerSource>1.7</compilerSource>
- <compilerCompliance>1.7</compilerCompliance>
- <compilerTargetPlatform>1.7</compilerTargetPlatform>
- </configuration>
- </plugin>
- <plugin>
- <artifactId>maven-dependency-plugin</artifactId>
- <executions>
- <execution>
- <phase>install</phase>
- <goals>
- <goal>copy-dependencies</goal>
- </goals>
- <configuration>
- <outputDirectory>${project.build.directory}/../lib</outputDirectory>
- </configuration>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-jar-plugin</artifactId>
- <version>2.5</version>
- <configuration>
- <archive>
- <manifest>
- <addClasspath>true</addClasspath>
- <classpathPrefix>../lib/</classpathPrefix>
- <mainClass>de.ids_mannheim.korap.query.serialize.QuerySerializer</mainClass>
- </manifest>
- </archive>
- </configuration>
- </plugin>
- <plugin>
- <!-- This plugin will help to build the ANTLR4 grammar on the fly. The
- recipe is based on http://stackoverflow.com/questions/15310628/ customize-maven-to-automatically-create-antlr4-grammar-java-files-on-build -->
- <groupId>org.antlr</groupId>
- <artifactId>antlr4-maven-plugin</artifactId>
- <version>4.1</version>
- <executions>
- <execution>
- <id>poliqarpplus</id>
- <goals>
- <goal>antlr4</goal>
- </goals>
- <configuration>
- <sourceDirectory>${basedir}/src/main/antlr/poliqarpplus</sourceDirectory>
- <outputDirectory>${basedir}/src/main/java/de/ids_mannheim/korap/query/parse/poliqarpplus</outputDirectory>
- <libDirectory>${basedir}/src/main/antlr/poliqarpplus</libDirectory>
- </configuration>
- <phase>generate-sources</phase>
- </execution>
- <execution>
- <id>annis</id>
- <goals>
- <goal>antlr4</goal>
- </goals>
- <configuration>
- <sourceDirectory>${basedir}/src/main/antlr/annis</sourceDirectory>
- <outputDirectory>${basedir}/src/main/java/de/ids_mannheim/korap/query/parse/annis</outputDirectory>
- <libDirectory>${basedir}/src/main/antlr/annis</libDirectory>
- </configuration>
- <phase>generate-sources</phase>
- </execution>
- <execution>
- <id>collection</id>
- <goals>
- <goal>antlr4</goal>
- </goals>
- <configuration>
- <sourceDirectory>${basedir}/src/main/antlr/collection</sourceDirectory>
- <outputDirectory>${basedir}/src/main/java/de/ids_mannheim/korap/query/parse/collection</outputDirectory>
- <libDirectory>${basedir}/src/main/antlr/collection</libDirectory>
- </configuration>
- <phase>generate-sources</phase>
- </execution>
- </executions>
- </plugin>
- <plugin>
- <!-- This plugin will help to build the ANTLR3 grammar on the fly. The
- recipe is based on http://stackoverflow.com/questions/15310628/ customize-maven-to-automatically-create-antlr4-grammar-java-files-on-build -->
- <groupId>org.antlr</groupId>
- <artifactId>antlr3-maven-plugin</artifactId>
- <version>3.5.1</version>
- <configuration>
- <sourceDirectory>${basedir}/src/main/antlr/cosmas</sourceDirectory>
- <outputDirectory>${basedir}/src/main/java/de/ids_mannheim/korap/query/parse/cosmas</outputDirectory>
- <libDirectory>${basedir}/src/main/antlr</libDirectory>
- </configuration>
-
- <executions>
- <execution>
- <goals>
- <goal>antlr</goal>
- </goals>
- <phase>generate-sources</phase>
- </execution>
- </executions>
-
- </plugin>
- <plugin>
- <artifactId>maven-compiler-plugin</artifactId>
- <version>2.3.2</version>
- <configuration>
- <source>1.7</source>
- <target>1.7</target>
- <!-- excludes> <exclude>**/CosmasTree.java</exclude> </excludes -->
- </configuration>
- </plugin>
- </plugins>
- </build>
+ <groupId>KorAP-modules</groupId>
+ <artifactId>Koral</artifactId>
+ <version>0.2</version>
+ <packaging>jar</packaging>
+ <name>Koral</name>
+ <url>http://maven.apache.org</url>
+ <repositories>
+ <repository>
+ <id>id-maven-repo</id>
+ <url>http://maven.indexdata.com</url>
+ </repository>
+ </repositories>
+ <dependencies>
+ <dependency>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr4-runtime</artifactId>
+ <version>4.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr4-maven-plugin</artifactId>
+ <version>4.1</version>
+ </dependency>
+ <dependency>
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr-runtime</artifactId>
+ <version>3.5</version>
+ <scope>compile</scope>
+ </dependency>
+ <dependency>
+ <groupId>com.google.guava</groupId>
+ <artifactId>guava</artifactId>
+ <version>15.0</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-core</artifactId>
+ <version>2.3.3</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-annotations</artifactId>
+ <version>2.3.3</version>
+ </dependency>
+ <dependency>
+ <groupId>com.fasterxml.jackson.core</groupId>
+ <artifactId>jackson-databind</artifactId>
+ <version>2.3.3</version>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <version>4.11</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-lang</groupId>
+ <artifactId>commons-lang</artifactId>
+ <version>2.6</version>
+ </dependency>
+ <dependency>
+ <groupId>org.z3950.zing</groupId>
+ <artifactId>cql-java</artifactId>
+ <version>1.12</version>
+ </dependency>
+ <dependency>
+ <groupId>org.projectlombok</groupId>
+ <artifactId>lombok</artifactId>
+ <version>0.11.8</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>log4j</artifactId>
+ <version>1.2.17</version>
+ </dependency>
+ <dependency>
+ <groupId>log4j</groupId>
+ <artifactId>apache-log4j-extras</artifactId>
+ <version>1.2.17</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-api</artifactId>
+ <version>1.7.5</version>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-log4j12</artifactId>
+ <version>1.7.5</version>
+ </dependency>
+ </dependencies>
+ <build>
+ <sourceDirectory>${basedir}/src/main/java</sourceDirectory>
+ <outputDirectory>${basedir}/target/classes</outputDirectory>
+ <plugins>
+ <!--
+ Formatter plugin for Eclipse based coding conventions
+ http://maven-java-formatter-plugin.googlecode.com/svn/site/0.4/usage.html
+ -->
+ <plugin>
+ <groupId>com.googlecode.maven-java-formatter-plugin</groupId>
+ <artifactId>maven-java-formatter-plugin</artifactId>
+ <version>0.4</version>
+ <configuration>
+ <configFile>${project.basedir}/Format.xml</configFile>
+ <overrideConfigCompilerVersion>true</overrideConfigCompilerVersion>
+ <compilerSource>1.7</compilerSource>
+ <compilerCompliance>1.7</compilerCompliance>
+ <compilerTargetPlatform>1.7</compilerTargetPlatform>
+ </configuration>
+ </plugin>
+ <plugin>
+ <artifactId>maven-dependency-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>install</phase>
+ <goals>
+ <goal>copy-dependencies</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${project.build.directory}/../lib</outputDirectory>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <version>2.5</version>
+ <configuration>
+ <archive>
+ <manifest>
+ <addClasspath>true</addClasspath>
+ <classpathPrefix>../lib/</classpathPrefix>
+ <mainClass>de.ids_mannheim.korap.query.serialize.QuerySerializer</mainClass>
+ </manifest>
+ </archive>
+ </configuration>
+ </plugin>
+ <plugin>
+ <!-- This plugin will help to build the ANTLR4 grammar on the fly. The
+ recipe is based on http://stackoverflow.com/questions/15310628/ customize-maven-to-automatically-create-antlr4-grammar-java-files-on-build -->
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr4-maven-plugin</artifactId>
+ <version>4.1</version>
+ <executions>
+ <execution>
+ <id>poliqarpplus</id>
+ <goals>
+ <goal>antlr4</goal>
+ </goals>
+ <configuration>
+ <sourceDirectory>${basedir}/src/main/antlr/poliqarpplus</sourceDirectory>
+ <outputDirectory>${basedir}/src/main/java/de/ids_mannheim/korap/query/parse/poliqarpplus</outputDirectory>
+ <libDirectory>${basedir}/src/main/antlr/poliqarpplus</libDirectory>
+ </configuration>
+ <phase>generate-sources</phase>
+ </execution>
+ <execution>
+ <id>annis</id>
+ <goals>
+ <goal>antlr4</goal>
+ </goals>
+ <configuration>
+ <sourceDirectory>${basedir}/src/main/antlr/annis</sourceDirectory>
+ <outputDirectory>${basedir}/src/main/java/de/ids_mannheim/korap/query/parse/annis</outputDirectory>
+ <libDirectory>${basedir}/src/main/antlr/annis</libDirectory>
+ </configuration>
+ <phase>generate-sources</phase>
+ </execution>
+ <execution>
+ <id>collection</id>
+ <goals>
+ <goal>antlr4</goal>
+ </goals>
+ <configuration>
+ <sourceDirectory>${basedir}/src/main/antlr/collection</sourceDirectory>
+ <outputDirectory>${basedir}/src/main/java/de/ids_mannheim/korap/query/parse/collection</outputDirectory>
+ <libDirectory>${basedir}/src/main/antlr/collection</libDirectory>
+ </configuration>
+ <phase>generate-sources</phase>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <!-- This plugin will help to build the ANTLR3 grammar on the fly. The
+ recipe is based on http://stackoverflow.com/questions/15310628/ customize-maven-to-automatically-create-antlr4-grammar-java-files-on-build -->
+ <groupId>org.antlr</groupId>
+ <artifactId>antlr3-maven-plugin</artifactId>
+ <version>3.5.1</version>
+ <configuration>
+ <sourceDirectory>${basedir}/src/main/antlr/cosmas</sourceDirectory>
+ <outputDirectory>${basedir}/src/main/java/de/ids_mannheim/korap/query/parse/cosmas</outputDirectory>
+ <libDirectory>${basedir}/src/main/antlr</libDirectory>
+ </configuration>
+
+ <executions>
+ <execution>
+ <goals>
+ <goal>antlr</goal>
+ </goals>
+ <phase>generate-sources</phase>
+ </execution>
+ </executions>
+
+ </plugin>
+ <plugin>
+ <artifactId>maven-compiler-plugin</artifactId>
+ <version>2.3.2</version>
+ <configuration>
+ <source>1.7</source>
+ <target>1.7</target>
+ <!-- excludes> <exclude>**/CosmasTree.java</exclude> </excludes -->
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
</project>
diff --git a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/IErrorReporter.java b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/IErrorReporter.java
index 9f92c7b..a209299 100644
--- a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/IErrorReporter.java
+++ b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/IErrorReporter.java
@@ -1,5 +1,5 @@
package de.ids_mannheim.korap.query.parse.cosmas;
public interface IErrorReporter {
- void reportError(String error);
+ void reportError (String error);
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opAnnot.java b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opAnnot.java
index 593988d..7ba505c 100644
--- a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opAnnot.java
+++ b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opAnnot.java
@@ -11,22 +11,19 @@
{
- public static String strip(String input)
- {
- if( input.startsWith("MORPH(") )
- {
- input = input.substring(6,input.length()-1);
- }
+ public static String strip (String input) {
+ if (input.startsWith("MORPH(")) {
+ input = input.substring(6, input.length() - 1);
+ }
- return input;
- }
+ return input;
+ }
- /*
- * main: testprogram:
- */
- public static void main(String args[]) throws Exception
- {
- } // main
+ /*
+ * main: testprogram:
+ */
-}
+ public static void main (String args[]) throws Exception {} // main
+
+}
diff --git a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opBED.java b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opBED.java
index 713c289..fb9df4e 100644
--- a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opBED.java
+++ b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opBED.java
@@ -9,91 +9,74 @@
{
- public static Tree check(String input, int index)
- {
- ANTLRStringStream
- ss = new ANTLRStringStream(input);
- c2ps_opBEDLexer
- lex = new c2ps_opBEDLexer(ss);
- CommonTokenStream tokens =
- new CommonTokenStream(lex);
- c2ps_opBEDParser
- g = new c2ps_opBEDParser(tokens);
- c2ps_opBEDParser.opBEDOpts_return
- c2PQReturn = null;
+ public static Tree check (String input, int index) {
+ ANTLRStringStream ss = new ANTLRStringStream(input);
+ c2ps_opBEDLexer lex = new c2ps_opBEDLexer(ss);
+ CommonTokenStream tokens = new CommonTokenStream(lex);
+ c2ps_opBEDParser g = new c2ps_opBEDParser(tokens);
+ c2ps_opBEDParser.opBEDOpts_return c2PQReturn = null;
- /*
- System.out.println("check opBED: " + index + ": " + input);
- System.out.flush();
- */
+ /*
+ System.out.println("check opBED: " + index + ": " + input);
+ System.out.flush();
+ */
- try
- {
- c2PQReturn = g.opBEDOpts();
- }
- catch (RecognitionException e)
- {
- e.printStackTrace();
- }
+ try {
+ c2PQReturn = g.opBEDOpts();
+ }
+ catch (RecognitionException e) {
+ e.printStackTrace();
+ }
- // AST Tree anzeigen:
- Tree tree = (Tree)c2PQReturn.getTree();
- //System.out.println("#BED Opts: " + tree.toStringTree() );
+ // AST Tree anzeigen:
+ Tree tree = (Tree) c2PQReturn.getTree();
+ //System.out.println("#BED Opts: " + tree.toStringTree() );
- return tree;
- }
+ return tree;
+ }
- /*
- * check Text Position starting at rule textpos.
- */
- public static Tree checkTPos(String input, int index)
- {
- ANTLRStringStream
- ss = new ANTLRStringStream(input);
- c2ps_opBEDLexer
- lex = new c2ps_opBEDLexer(ss);
- CommonTokenStream tokens =
- new CommonTokenStream(lex);
- c2ps_opBEDParser
- g = new c2ps_opBEDParser(tokens);
- c2ps_opBEDParser.textpos_return
- c2PQReturn = null;
+ /*
+ * check Text Position starting at rule textpos.
+ */
- /*
- System.out.println("check opBED: " + index + ": " + input);
- System.out.flush();
- */
+ public static Tree checkTPos (String input, int index) {
+ ANTLRStringStream ss = new ANTLRStringStream(input);
+ c2ps_opBEDLexer lex = new c2ps_opBEDLexer(ss);
+ CommonTokenStream tokens = new CommonTokenStream(lex);
+ c2ps_opBEDParser g = new c2ps_opBEDParser(tokens);
+ c2ps_opBEDParser.textpos_return c2PQReturn = null;
- try
- {
- c2PQReturn = g.textpos();
- }
- catch (RecognitionException e)
- {
- e.printStackTrace();
- }
+ /*
+ System.out.println("check opBED: " + index + ": " + input);
+ System.out.flush();
+ */
- // AST Tree anzeigen:
- Tree tree = (Tree)c2PQReturn.getTree();
- // System.out.println("#BED Opts: " + tree.toStringTree() );
+ try {
+ c2PQReturn = g.textpos();
+ }
+ catch (RecognitionException e) {
+ e.printStackTrace();
+ }
- return tree;
- }
+ // AST Tree anzeigen:
+ Tree tree = (Tree) c2PQReturn.getTree();
+ // System.out.println("#BED Opts: " + tree.toStringTree() );
- public static void main(String args[]) throws Exception
- {
- String[]
- input = {",sa,se,-ta,-te/pa,-pe)", ",sa)", ",/pa,-pe)"};
- Tree
- tree;
+ return tree;
+ }
- for(int i=0; i<input.length; i++)
- {
- tree = check(input[i], 0);
- System.out.println("Parsing input: " + input[i] + ": " + tree.toStringTree());
- }
- } // main
+ public static void main (String args[]) throws Exception {
+ String[] input = { ",sa,se,-ta,-te/pa,-pe)", ",sa)", ",/pa,-pe)" };
+ Tree tree;
-}
+ for (int i = 0; i < input.length; i++) {
+ tree = check(input[i], 0);
+ System.out.println("Parsing input: " + input[i] + ": "
+ + tree.toStringTree());
+ }
+
+ } // main
+
+}
diff --git a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opELEM.java b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opELEM.java
index 2e0c55c..129ba49 100644
--- a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opELEM.java
+++ b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opELEM.java
@@ -9,69 +9,55 @@
{
- /* Method check():
- * input: e.g. #ELEM(S), #ELEM(W ANA='DET ADJ'),
- * #ELEM(ANA <> 'V sg' TYP !=VP), etc.
- */
- public static Tree check(String input, int index)
- {
- ANTLRStringStream
- ss = new ANTLRStringStream(input);
- c2ps_opELEMLexer
- lex = new c2ps_opELEMLexer(ss);
- CommonTokenStream tokens =
- new CommonTokenStream(lex);
- c2ps_opELEMParser
- g = new c2ps_opELEMParser(tokens);
- c2ps_opELEMParser.opELEM_return
- c2PQReturn = null;
+ /* Method check():
+ * input: e.g. #ELEM(S), #ELEM(W ANA='DET ADJ'),
+ * #ELEM(ANA <> 'V sg' TYP !=VP), etc.
+ */
+ public static Tree check (String input, int index) {
+ ANTLRStringStream ss = new ANTLRStringStream(input);
+ c2ps_opELEMLexer lex = new c2ps_opELEMLexer(ss);
+ CommonTokenStream tokens = new CommonTokenStream(lex);
+ c2ps_opELEMParser g = new c2ps_opELEMParser(tokens);
+ c2ps_opELEMParser.opELEM_return c2PQReturn = null;
- /*
- System.out.println("check opELEM: " + index + ": " + "'" + input + "'");
- System.out.flush();
- */
+ /*
+ System.out.println("check opELEM: " + index + ": " + "'" + input + "'");
+ System.out.flush();
+ */
- try
- {
- c2PQReturn = g.opELEM();
- }
- catch (RecognitionException e)
- {
- e.printStackTrace();
- }
+ try {
+ c2PQReturn = g.opELEM();
+ }
+ catch (RecognitionException e) {
+ e.printStackTrace();
+ }
- // AST Tree anzeigen:
- Tree tree = (Tree)c2PQReturn.getTree();
- //System.out.println("#ELEM Opts: " + tree.toStringTree() );
+ // AST Tree anzeigen:
+ Tree tree = (Tree) c2PQReturn.getTree();
+ //System.out.println("#ELEM Opts: " + tree.toStringTree() );
- return tree;
- }
+ return tree;
+ }
- /*
- * main - Testprogramm for #ELEM(...)
- */
+ /*
+ * main - Testprogramm for #ELEM(...)
+ */
- public static void main(String args[]) throws Exception
- {
- String[]
- input = {"#ELEM()",
- "#ELEM( )",
- "#ELEM(S)",
- "#ELEM(W ANA='DET ADV')",
- "#ELEM( TITLE TYPE!=Unterüberschrift )",
- "#ELEM(v='a b c' w!='d e f' x=y )",
- "#ELEM(flexion='l\\'été' lemma='été')"};
- Tree
- tree;
+ public static void main (String args[]) throws Exception {
+ String[] input = { "#ELEM()", "#ELEM( )", "#ELEM(S)",
+ "#ELEM(W ANA='DET ADV')",
+ "#ELEM( TITLE TYPE!=Unterüberschrift )",
+ "#ELEM(v='a b c' w!='d e f' x=y )",
+ "#ELEM(flexion='l\\'été' lemma='été')" };
+ Tree tree;
- for(int i=0; i<input.length; i++)
- {
- System.out.println("#ELEM input: " + input[i]);
- tree = check(input[i], 0);
- System.out.println("#ELEM AST : " + tree.toStringTree());
- }
+ for (int i = 0; i < input.length; i++) {
+ System.out.println("#ELEM input: " + input[i]);
+ tree = check(input[i], 0);
+ System.out.println("#ELEM AST : " + tree.toStringTree());
+ }
- } // main
+ } // main
-}
+}
diff --git a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opIN.java b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opIN.java
index 53f6429..859c68b 100644
--- a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opIN.java
+++ b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opIN.java
@@ -21,61 +21,50 @@
{
- public static Tree check(String input, int index)
- {
- ANTLRStringStream
- ss = new ANTLRStringStream(input);
- c2ps_opINLexer
- lex = new c2ps_opINLexer(ss);
- CommonTokenStream tokens =
- new CommonTokenStream(lex);
- c2ps_opINParser
- g = new c2ps_opINParser(tokens);
- c2ps_opINParser.opIN_return
- c2PQReturn = null;
+ public static Tree check (String input, int index) {
+ ANTLRStringStream ss = new ANTLRStringStream(input);
+ c2ps_opINLexer lex = new c2ps_opINLexer(ss);
+ CommonTokenStream tokens = new CommonTokenStream(lex);
+ c2ps_opINParser g = new c2ps_opINParser(tokens);
+ c2ps_opINParser.opIN_return c2PQReturn = null;
- /*
- System.out.println("check opIN:" + index + ": " + input);
- System.out.flush();
- */
+ /*
+ System.out.println("check opIN:" + index + ": " + input);
+ System.out.flush();
+ */
- try
- {
- c2PQReturn = g.opIN();
- }
- catch (RecognitionException e)
- {
- e.printStackTrace();
- }
+ try {
+ c2PQReturn = g.opIN();
+ }
+ catch (RecognitionException e) {
+ e.printStackTrace();
+ }
- // AST Tree anzeigen:
- Tree tree = (Tree)c2PQReturn.getTree();
- // System.out.println("opIN: " + tree.toStringTree() );
+ // AST Tree anzeigen:
+ Tree tree = (Tree) c2PQReturn.getTree();
+ // System.out.println("opIN: " + tree.toStringTree() );
- return tree;
- }
+ return tree;
+ }
- /*
- * main: testprogram:
- */
- public static void main(String args[]) throws Exception
- {
- String[]
- input = {"#IN", "#IN()", "#IN(L)", "#IN(FE,min)", "#IN(R,%,max)", "#IN(FI,ALL)",
- "#IN(FE,ALL,%,MIN)"};
- Tree
- tree;
+ /*
+ * main: testprogram:
+ */
- System.out.println("Tests von #IN-Optionen:\n");
+ public static void main (String args[]) throws Exception {
+ String[] input = { "#IN", "#IN()", "#IN(L)", "#IN(FE,min)",
+ "#IN(R,%,max)", "#IN(FI,ALL)", "#IN(FE,ALL,%,MIN)" };
+ Tree tree;
- for(int i=0; i<input.length; i++)
- {
- tree = check(input[i], 0);
- System.out.println("#IN: input: " + input[i]);
- System.out.println("#IN: AST : " + tree.toStringTree() + "\n");
- }
+ System.out.println("Tests von #IN-Optionen:\n");
- } // main
+ for (int i = 0; i < input.length; i++) {
+ tree = check(input[i], 0);
+ System.out.println("#IN: input: " + input[i]);
+ System.out.println("#IN: AST : " + tree.toStringTree() + "\n");
+ }
-}
+ } // main
+
+}
diff --git a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opOV.java b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opOV.java
index 27cd9de..6526935 100644
--- a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opOV.java
+++ b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opOV.java
@@ -20,61 +20,50 @@
{
- public static Tree check(String input, int index)
- {
- ANTLRStringStream
- ss = new ANTLRStringStream(input);
- c2ps_opOVLexer
- lex = new c2ps_opOVLexer(ss);
- CommonTokenStream tokens =
- new CommonTokenStream(lex);
- c2ps_opOVParser
- g = new c2ps_opOVParser(tokens);
- c2ps_opOVParser.opOV_return
- c2PQReturn = null;
+ public static Tree check (String input, int index) {
+ ANTLRStringStream ss = new ANTLRStringStream(input);
+ c2ps_opOVLexer lex = new c2ps_opOVLexer(ss);
+ CommonTokenStream tokens = new CommonTokenStream(lex);
+ c2ps_opOVParser g = new c2ps_opOVParser(tokens);
+ c2ps_opOVParser.opOV_return c2PQReturn = null;
- try
- {
- c2PQReturn = g.opOV();
- }
- catch (RecognitionException e)
- {
- e.printStackTrace();
- }
+ try {
+ c2PQReturn = g.opOV();
+ }
+ catch (RecognitionException e) {
+ e.printStackTrace();
+ }
- // AST Tree anzeigen:
- Tree tree = (Tree)c2PQReturn.getTree();
- // System.out.println("opOV: " + tree.toStringTree() );
+ // AST Tree anzeigen:
+ Tree tree = (Tree) c2PQReturn.getTree();
+ // System.out.println("opOV: " + tree.toStringTree() );
- return tree;
- }
+ return tree;
+ }
- /*
- * main: testprogram:
- */
- // TODOO: input "OV()" führt zu unendlichem loop... 19.12.12/FB
- // TODOO: input "#OV(FI,ALL)" -> loop, weil ALL nicht bekannter Token...
+ /*
+ * main: testprogram:
+ */
- public static void main(String args[]) throws Exception
- {
- String[]
- input = {"#OV", "#OV()", "#OV(L)", "#OV(FE,min)", "#OV(R,% , max)"};
- Tree
- tree;
+ // TODOO: input "OV()" führt zu unendlichem loop... 19.12.12/FB
+ // TODOO: input "#OV(FI,ALL)" -> loop, weil ALL nicht bekannter Token...
- System.out.println("Tests von #OV-Optionen:\n");
+ public static void main (String args[]) throws Exception {
+ String[] input = { "#OV", "#OV()", "#OV(L)", "#OV(FE,min)",
+ "#OV(R,% , max)" };
+ Tree tree;
- for(int i=0; i<input.length; i++)
- {
- System.out.println("#OV: input: " + input[i]);
- tree = check(input[i], 0);
- System.out.println("#OV: AST : " + tree.toStringTree() + "\n");
- }
+ System.out.println("Tests von #OV-Optionen:\n");
- System.out.println("Tests von #OV-Optionen: quit.\n");
- System.out.flush();
- } // main
+ for (int i = 0; i < input.length; i++) {
+ System.out.println("#OV: input: " + input[i]);
+ tree = check(input[i], 0);
+ System.out.println("#OV: AST : " + tree.toStringTree() + "\n");
+ }
-}
+ System.out.println("Tests von #OV-Optionen: quit.\n");
+ System.out.flush();
+ } // main
+}
diff --git a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opPROX.java b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opPROX.java
index 12d8fa4..2a5b163 100644
--- a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opPROX.java
+++ b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opPROX.java
@@ -11,67 +11,56 @@
{
- public static Tree check(String input, int index)
- {
- ANTLRStringStream
- ss = new ANTLRStringStream(input);
- c2ps_opPROXLexer
- lex = new c2ps_opPROXLexer(ss);
- CommonTokenStream tokens =
- new CommonTokenStream(lex);
- c2ps_opPROXParser
- g = new c2ps_opPROXParser(tokens);
- c2ps_opPROXParser.opPROX_return
- c2PQReturn = null;
+ public static Tree check (String input, int index) {
+ ANTLRStringStream ss = new ANTLRStringStream(input);
+ c2ps_opPROXLexer lex = new c2ps_opPROXLexer(ss);
+ CommonTokenStream tokens = new CommonTokenStream(lex);
+ c2ps_opPROXParser g = new c2ps_opPROXParser(tokens);
+ c2ps_opPROXParser.opPROX_return c2PQReturn = null;
- /*
- System.out.println("check opPROX:" + index + ": " + input);
- System.out.flush();
- */
+ /*
+ System.out.println("check opPROX:" + index + ": " + input);
+ System.out.flush();
+ */
- try
- {
- c2PQReturn = g.opPROX();
- }
- catch (RecognitionException e)
- {
- e.printStackTrace();
- }
+ try {
+ c2PQReturn = g.opPROX();
+ }
+ catch (RecognitionException e) {
+ e.printStackTrace();
+ }
- // AST Tree anzeigen:
- Tree tree = (Tree)c2PQReturn.getTree();
- //System.out.println("PROX: " + tree.toStringTree() );
+ // AST Tree anzeigen:
+ Tree tree = (Tree) c2PQReturn.getTree();
+ //System.out.println("PROX: " + tree.toStringTree() );
- return tree;
- }
+ return tree;
+ }
- /*
- * main testprogram:
- */
- public static void main(String args[]) throws Exception
- {
- String[]
- input = {"/w1:3", "%w5", "/+w3,s0,max"};
- Tree
- tree;
+ /*
+ * main testprogram:
+ */
- System.out.println("Tests von PROX-Optionen:\n");
+ public static void main (String args[]) throws Exception {
+ String[] input = { "/w1:3", "%w5", "/+w3,s0,max" };
+ Tree tree;
- for(int i=0; i<input.length; i++)
- {
- tree = check(input[i], 0);
- System.out.println("PROX: input: " + input[i]);
- System.out.println("PROX: AST : " + tree.toStringTree() + "\n");
-
- // Visualize AST Tree:
- /*
- DOTTreeGenerator gen = new DOTTreeGenerator();
- StringTemplate st = gen.toDOT(tree);
- System.out.println("DOTTREE: " + st);
- */
- }
+ System.out.println("Tests von PROX-Optionen:\n");
- } // main
+ for (int i = 0; i < input.length; i++) {
+ tree = check(input[i], 0);
+ System.out.println("PROX: input: " + input[i]);
+ System.out.println("PROX: AST : " + tree.toStringTree() + "\n");
-}
+ // Visualize AST Tree:
+ /*
+ DOTTreeGenerator gen = new DOTTreeGenerator();
+ StringTemplate st = gen.toDOT(tree);
+ System.out.println("DOTTREE: " + st);
+ */
+ }
+
+ } // main
+
+}
diff --git a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opWF.java b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opWF.java
index 7cdac48..f107d41 100644
--- a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opWF.java
+++ b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_opWF.java
@@ -11,114 +11,103 @@
public class c2ps_opWF
{
- /* Arguments:
- * bStrip: true: 'input' contains "wort" -> strip " away -> wort.
- * false: 'input' contains no " -> nothing to strip.
- * bLem: true: input contains a Lemma; generates tree ^(OPLEM...).
- * false: input contains a Wordform; generates tree ^(OPWF...).
- * input: may be a single Lemma or Wform or a list of Wforms.
- */
+ /* Arguments:
+ * bStrip: true: 'input' contains "wort" -> strip " away -> wort.
+ * false: 'input' contains no " -> nothing to strip.
+ * bLem: true: input contains a Lemma; generates tree ^(OPLEM...).
+ * false: input contains a Wordform; generates tree ^(OPWF...).
+ * input: may be a single Lemma or Wform or a list of Wforms.
+ */
- public static Tree check(String input, boolean bStrip, boolean bLem, int index)
- {
- if( bStrip )
- input = input.substring(1, input.length()-1);
+ public static Tree check (String input, boolean bStrip, boolean bLem,
+ int index) {
+ if (bStrip)
+ input = input.substring(1, input.length() - 1);
- if( bLem && input.charAt(0) == '&' )
- {
- input = input.substring(1, input.length());
- //System.out.println("Lemma: strip '&' -> " + input);
- }
+ if (bLem && input.charAt(0) == '&') {
+ input = input.substring(1, input.length());
+ //System.out.println("Lemma: strip '&' -> " + input);
+ }
- ANTLRStringStream
- ss = new ANTLRStringStream(input);
- c2ps_opWFLexer
- lex = new c2ps_opWFLexer(ss);
- CommonTokenStream tokens =
- new CommonTokenStream(lex);
- c2ps_opWFParser
- g = new c2ps_opWFParser(tokens);
- c2ps_opWFParser.searchWFs_return
- c2PQWFReturn = null;
- c2ps_opWFParser.searchLEM_return
- c2PQLEMReturn = null;
+ ANTLRStringStream ss = new ANTLRStringStream(input);
+ c2ps_opWFLexer lex = new c2ps_opWFLexer(ss);
+ CommonTokenStream tokens = new CommonTokenStream(lex);
+ c2ps_opWFParser g = new c2ps_opWFParser(tokens);
+ c2ps_opWFParser.searchWFs_return c2PQWFReturn = null;
+ c2ps_opWFParser.searchLEM_return c2PQLEMReturn = null;
- /*
- System.out.println("check opWF:" + index + ": " + input);
- System.out.flush();
- */
-
- try
- {
- if( bLem )
- c2PQLEMReturn = g.searchLEM();
- else
- c2PQWFReturn = g.searchWFs();
- }
- catch (RecognitionException e)
- {
- e.printStackTrace();
- }
+ /*
+ System.out.println("check opWF:" + index + ": " + input);
+ System.out.flush();
+ */
- // AST Tree anzeigen:
- Tree tree = bLem ? (Tree)c2PQLEMReturn.getTree() : (Tree)c2PQWFReturn.getTree();
- // System.out.println(bLem? "opLEM: " : "opWF: " + tree.toStringTree() );
+ try {
+ if (bLem)
+ c2PQLEMReturn = g.searchLEM();
+ else
+ c2PQWFReturn = g.searchWFs();
+ }
+ catch (RecognitionException e) {
+ e.printStackTrace();
+ }
- return tree;
- }
+ // AST Tree anzeigen:
+ Tree tree = bLem ? (Tree) c2PQLEMReturn.getTree() : (Tree) c2PQWFReturn
+ .getTree();
+ // System.out.println(bLem? "opLEM: " : "opWF: " + tree.toStringTree() );
- /* Wordform Encoding, e.g. to insert a Wordform into an AST.
- * a) wf -> "wf".
- * b) remove escape char before ':': abc\: -> abc:.
- * Returns a Tree.
- */
- public static Tree encode(String wf, int tokenType)
+ return tree;
+ }
- {
- // b)
- StringBuffer
- sbWF = new StringBuffer(wf);
-
- for(int i=0; i<sbWF.length()-1; i++)
- {
- if( sbWF.charAt(i) == '\\' && sbWF.charAt(i+1) == ':' )
- sbWF.deleteCharAt(i);
- }
- return new CommonTree(new CommonToken(tokenType, "\"" + sbWF.toString() + "\""));
- }
+ /* Wordform Encoding, e.g. to insert a Wordform into an AST.
+ * a) wf -> "wf".
+ * b) remove escape char before ':': abc\: -> abc:.
+ * Returns a Tree.
+ */
+ public static Tree encode (String wf, int tokenType)
- /*
- * main testprogram:
- */
+ {
+ // b)
+ StringBuffer sbWF = new StringBuffer(wf);
- public static void main(String args[]) throws Exception
- {
- String[]
- input = {":fi:Hendrix:sa", ":FiOlDs:été:sa", "&Gitarre", "&Gitarre:sa/-pe",
- " \"Institut für \\:Deutsche\\: Sprache\" ",
- ":Fi:der:-sa Wilde:-se Western:/se" };
- Tree
- tree;
- boolean
- bLem;
+ for (int i = 0; i < sbWF.length() - 1; i++) {
+ if (sbWF.charAt(i) == '\\' && sbWF.charAt(i + 1) == ':')
+ sbWF.deleteCharAt(i);
+ }
- System.out.println("Tests von WF und Lemma-Optionen:\n");
+ return new CommonTree(new CommonToken(tokenType, "\"" + sbWF.toString()
+ + "\""));
+ }
- for(int i=0; i<input.length; i++)
- {
- bLem = input[i].charAt(0) == '&' ? true : false;
- System.out.println(bLem? "LEM: " : "WF: " + "input: " + input[i]);
+ /*
+ * main testprogram:
+ */
- if( bLem )
- tree = check(input[i], false, true, 0); // bStrip=false, bLem=true;
- else
- tree = check(input[i], false, false, 0); // bStrip=false, bLem=false.
-
- System.out.println(bLem? "LEM: " : "WF: " + "AST : " + tree.toStringTree() + "\n");
- }
+ public static void main (String args[]) throws Exception {
+ String[] input = { ":fi:Hendrix:sa", ":FiOlDs:été:sa", "&Gitarre",
+ "&Gitarre:sa/-pe", " \"Institut für \\:Deutsche\\: Sprache\" ",
+ ":Fi:der:-sa Wilde:-se Western:/se" };
+ Tree tree;
+ boolean bLem;
- } // main
+ System.out.println("Tests von WF und Lemma-Optionen:\n");
-}
+ for (int i = 0; i < input.length; i++) {
+ bLem = input[i].charAt(0) == '&' ? true : false;
+
+ System.out.println(bLem ? "LEM: " : "WF: " + "input: " + input[i]);
+
+ if (bLem)
+ tree = check(input[i], false, true, 0); // bStrip=false, bLem=true;
+ else
+ tree = check(input[i], false, false, 0); // bStrip=false, bLem=false.
+
+ System.out.println(bLem ? "LEM: " : "WF: " + "AST : "
+ + tree.toStringTree() + "\n");
+ }
+
+ } // main
+
+}
diff --git a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_optCase.java b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_optCase.java
index 8a971d6..a2c5a3c 100644
--- a/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_optCase.java
+++ b/src/main/java/de/ids_mannheim/korap/query/parse/cosmas/c2ps_optCase.java
@@ -9,58 +9,48 @@
{
- public static Tree check(String input, int index)
- {
- ANTLRStringStream
- ss = new ANTLRStringStream(input);
- c2ps_optCaseLexer
- lex = new c2ps_optCaseLexer(ss);
- CommonTokenStream tokens =
- new CommonTokenStream(lex);
- c2ps_optCaseParser
- g = new c2ps_optCaseParser(tokens);
- c2ps_optCaseParser.optCase_return
- c2PQReturn = null;
+ public static Tree check (String input, int index) {
+ ANTLRStringStream ss = new ANTLRStringStream(input);
+ c2ps_optCaseLexer lex = new c2ps_optCaseLexer(ss);
+ CommonTokenStream tokens = new CommonTokenStream(lex);
+ c2ps_optCaseParser g = new c2ps_optCaseParser(tokens);
+ c2ps_optCaseParser.optCase_return c2PQReturn = null;
- /*
- System.out.println("check optCase: " + index + ": " + input);
- System.out.flush();
- */
+ /*
+ System.out.println("check optCase: " + index + ": " + input);
+ System.out.flush();
+ */
- try
- {
- c2PQReturn = g.optCase();
- }
- catch (RecognitionException e)
- {
- e.printStackTrace();
- }
+ try {
+ c2PQReturn = g.optCase();
+ }
+ catch (RecognitionException e) {
+ e.printStackTrace();
+ }
- // AST Tree anzeigen:
- Tree tree = (Tree)c2PQReturn.getTree();
- //System.out.println("Case Opts: " + tree.toStringTree() );
+ // AST Tree anzeigen:
+ Tree tree = (Tree) c2PQReturn.getTree();
+ //System.out.println("Case Opts: " + tree.toStringTree() );
- return tree;
- }
+ return tree;
+ }
- /*
- * Main Text programm.
- *
- */
- public static void main(String args[]) throws Exception
- {
- String[]
- input = {"Fi", "FiOsDi"};
- Tree
- tree;
+ /*
+ * Main Text programm.
+ *
+ */
- for(int i=0; i<input.length; i++)
- {
- tree = check(input[i], 0);
- System.out.println("Parsing input: " + input[i] + ": " + tree.toStringTree());
- }
+ public static void main (String args[]) throws Exception {
+ String[] input = { "Fi", "FiOsDi" };
+ Tree tree;
- } // main
+ for (int i = 0; i < input.length; i++) {
+ tree = check(input[i], 0);
+ System.out.println("Parsing input: " + input[i] + ": "
+ + tree.toStringTree());
+ }
-}
+ } // main
+
+}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractQueryProcessor.java
index 5c15114..60c2a51 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/AbstractQueryProcessor.java
@@ -11,11 +11,12 @@
import org.slf4j.Logger;
/**
- * This is an abstract class which provides fields and methods for concrete
- * query processor implementations. All of those must implement
+ * This is an abstract class which provides fields and methods for
+ * concrete
+ * query processor implementations. All of those must implement
* {@link #process(String)}, which is expected to process the query
* and store a {@link #java.util.Map} representation of the KoralQuery
- * JSON-LD tree for that query.
+ * JSON-LD tree for that query.
*
* @author Joachim Bingel (bingel@ids-mannheim.de)
* @version 0.3.0
@@ -25,14 +26,13 @@
Logger log;
/**
- * The query string.
+ * The query string.
*/
String query;
/**
* Top-level map representing the whole request.
*/
- LinkedHashMap<String, Object> requestMap =
- new LinkedHashMap<String, Object>();
+ LinkedHashMap<String, Object> requestMap = new LinkedHashMap<String, Object>();
/**
* Keeps track of open node categories.
*/
@@ -42,13 +42,14 @@
*/
List<ParseTree> visited = new ArrayList<ParseTree>();
/**
- * Keeps track of active object, used for inserting new KoralQuery objects
+ * Keeps track of active object, used for inserting new KoralQuery
+ * objects
* into last created objects.
*/
- LinkedList<LinkedHashMap<String, Object>> objectStack =
- new LinkedList<LinkedHashMap<String, Object>>();
+ LinkedList<LinkedHashMap<String, Object>> objectStack = new LinkedList<LinkedHashMap<String, Object>>();
/**
- * Keeps track of how many objects there are to pop after every recursion
+ * Keeps track of how many objects there are to pop after every
+ * recursion
* of {@link #processNode(ParseTree)}
*/
LinkedList<Integer> objectsToPop = new LinkedList<Integer>();
@@ -58,11 +59,13 @@
public static boolean verbose = false;
protected Integer stackedObjects = 0;
/**
- * Contains error arrays, consisting of an error code and a message.
+ * Contains error arrays, consisting of an error code and a
+ * message.
*/
private ArrayList<List<Object>> errors = new ArrayList<List<Object>>();
/**
- * Contains warning arrays, consisting of a warning code (optional) and a
+ * Contains warning arrays, consisting of a warning code
+ * (optional) and a
* message.
*/
private ArrayList<List<Object>> warnings = new ArrayList<List<Object>>();
@@ -73,24 +76,23 @@
/**
* Virtual collection queries.
*/
- private LinkedHashMap<String, Object> collection =
- new LinkedHashMap<String,Object>();
+ private LinkedHashMap<String, Object> collection = new LinkedHashMap<String, Object>();
/**
* Holds information on displaying directives.
*/
- private LinkedHashMap<String, Object> meta =
- new LinkedHashMap<String,Object>();
+ private LinkedHashMap<String, Object> meta = new LinkedHashMap<String, Object>();
/**
* Indicates which classes are to be highlighted in KWIC view.
*/
private ArrayList<Integer> highlightClasses = new ArrayList<Integer>();
-
+
/**
* Indicates positions of alignment rulers in KWIC view.
*/
private ArrayList<List<Integer>> alignments = new ArrayList<List<Integer>>();
- AbstractQueryProcessor() {
+
+ AbstractQueryProcessor () {
requestMap.put("@context",
"http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld");
requestMap.put("errors", errors);
@@ -101,92 +103,125 @@
requestMap.put("meta", meta);
}
+
/**
- * Called to process the query, is expected to generate a Map-based
- * KoralQuery representation in {@link #requestMap}.
- * @param query The query string.
+ * Called to process the query, is expected to generate a
+ * Map-based
+ * KoralQuery representation in {@link #requestMap}.
+ *
+ * @param query
+ * The query string.
*/
- public abstract void process(String query);
+ public abstract void process (String query);
+
/**
* Adds a warning to {@link #warnings}.
- * @param code The warning code.
- * @param msg The warning message.
+ *
+ * @param code
+ * The warning code.
+ * @param msg
+ * The warning message.
*/
- public void addWarning(int code, String msg) {
- List<Object> warning = Arrays.asList(new Object[]{code, msg});
+ public void addWarning (int code, String msg) {
+ List<Object> warning = Arrays.asList(new Object[] { code, msg });
warnings.add(warning);
}
+
/**
* Adds a warning to {@link #warnings}.
- * @param msg The warning message.
+ *
+ * @param msg
+ * The warning message.
*/
- public void addWarning(String msg) {
- List<Object> warning = Arrays.asList(new Object[]{msg});
+ public void addWarning (String msg) {
+ List<Object> warning = Arrays.asList(new Object[] { msg });
warnings.add(warning);
}
- /**
- * Adds a generic message to {@link #messages}.
- * @param code The message code.
- * @param msg The message string.
- */
- public void addMessage(int code, String msg) {
- List<Object> message = Arrays.asList(new Object[]{code, msg});
- messages.add(message);
- }
/**
* Adds a generic message to {@link #messages}.
- * @param msg The message string.
+ *
+ * @param code
+ * The message code.
+ * @param msg
+ * The message string.
*/
- public void addMessage(String msg) {
- List<Object> message = Arrays.asList(new Object[]{msg});
+ public void addMessage (int code, String msg) {
+ List<Object> message = Arrays.asList(new Object[] { code, msg });
messages.add(message);
}
+
+ /**
+ * Adds a generic message to {@link #messages}.
+ *
+ * @param msg
+ * The message string.
+ */
+ public void addMessage (String msg) {
+ List<Object> message = Arrays.asList(new Object[] { msg });
+ messages.add(message);
+ }
+
+
/**
* Adds an error to {@link #errors}.
- * @param code The error code.
- * @param msg The error message.
+ *
+ * @param code
+ * The error code.
+ * @param msg
+ * The error message.
*/
- public void addError(int code, String msg) {
- List<Object> error = Arrays.asList(new Object[]{code, msg});
+ public void addError (int code, String msg) {
+ List<Object> error = Arrays.asList(new Object[] { code, msg });
errors.add(error);
}
+
/**
* Adds an error to {@link #errors}.
- * @param fullErrorMsg First object is expected to be an integer
- * error code, second a message.
+ *
+ * @param fullErrorMsg
+ * First object is expected to be an integer
+ * error code, second a message.
*/
- public void addError(List<Object> fullErrorMsg) {
+ public void addError (List<Object> fullErrorMsg) {
errors.add(fullErrorMsg);
}
+
/**
* Add a class to the list of classes highlighted in KWIC view.
- * @param classId The class ID.
+ *
+ * @param classId
+ * The class ID.
*/
- public void addHighlightClass(int classId) {
+ public void addHighlightClass (int classId) {
highlightClasses.add(classId);
meta.put("highlight", highlightClasses);
}
-
- public void addAlignment(int leftClassId, int rightClassId) {
- List<Integer> alignment = Arrays.asList(new Integer[]{leftClassId, rightClassId});
+
+
+ public void addAlignment (int leftClassId, int rightClassId) {
+ List<Integer> alignment = Arrays.asList(new Integer[] { leftClassId,
+ rightClassId });
alignments.add(alignment);
meta.put("alignment", alignments);
}
+
/**
* Getter method for the {@link #requestMap}, which represents the
- * entire KoralQuery request (query, displaying directives, virtual
+ * entire KoralQuery request (query, displaying directives,
+ * virtual
* collections, messages etc.) based on a Java Map.
+ *
* @return
*/
- public Map<String, Object> getRequestMap() {
+ public Map<String, Object> getRequestMap () {
return requestMap;
}
}
\ No newline at end of file
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessor.java
index 2e9ac7b..528d799 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessor.java
@@ -27,10 +27,13 @@
import de.ids_mannheim.korap.query.serialize.util.StatusCodes;
/**
- * Processor class for ANNIS QL queries. This class uses an ANTLR v4 grammar
- * for query parsing, it therefore extends {@link Antlr4AbstractQueryProcessor}.
- * The parser object is inherited from the parent class and instantiated in
- * {@link #parseAnnisQuery(String)} as an {@link AqlParser}.
+ * Processor class for ANNIS QL queries. This class uses an ANTLR v4
+ * grammar
+ * for query parsing, it therefore extends
+ * {@link Antlr4AbstractQueryProcessor}.
+ * The parser object is inherited from the parent class and
+ * instantiated in {@link #parseAnnisQuery(String)} as an
+ * {@link AqlParser}.
*
* @see http://annis-tools.org/aql.html
*
@@ -39,152 +42,187 @@
* @since 0.1.0
*/
public class AnnisQueryProcessor extends Antlr4AbstractQueryProcessor {
- private static Logger log = LoggerFactory.getLogger(AnnisQueryProcessor.class);
+ private static Logger log = LoggerFactory
+ .getLogger(AnnisQueryProcessor.class);
/**
- * Flag that indicates whether token fields or meta fields are currently
+ * Flag that indicates whether token fields or meta fields are
+ * currently
* being processed
*/
boolean inMeta = false;
/**
- * Keeps track of operands that are to be integrated into yet uncreated
+ * Keeps track of operands that are to be integrated into yet
+ * uncreated
* objects.
*/
- LinkedList<LinkedHashMap<String,Object>> operandStack =
- new LinkedList<LinkedHashMap<String,Object>>();
+ LinkedList<LinkedHashMap<String, Object>> operandStack = new LinkedList<LinkedHashMap<String, Object>>();
/**
- * Keeps track of explicitly (by #-var definition) or implicitly (number
- * as reference) introduced entities (for later reference by #-operator)
+ * Keeps track of explicitly (by #-var definition) or implicitly
+ * (number
+ * as reference) introduced entities (for later reference by
+ * #-operator)
*/
- Map<String, LinkedHashMap<String,Object>> nodeVariables =
- new LinkedHashMap<String, LinkedHashMap<String,Object>>();
+ Map<String, LinkedHashMap<String, Object>> nodeVariables = new LinkedHashMap<String, LinkedHashMap<String, Object>>();
/**
- * Keeps track of explicitly (by #-var definition) or implicitly (number
- * as reference) introduced entities (for later reference by #-operator)
+ * Keeps track of explicitly (by #-var definition) or implicitly
+ * (number
+ * as reference) introduced entities (for later reference by
+ * #-operator)
*/
- Map<ParseTree, String> nodes2refs= new LinkedHashMap<ParseTree, String>();
+ Map<ParseTree, String> nodes2refs = new LinkedHashMap<ParseTree, String>();
/**
* Counter for variable definitions.
*/
Integer variableCount = 1;
/**
- * Marks the currently active token in order to know where to add flags
+ * Marks the currently active token in order to know where to add
+ * flags
* (might already have been taken away from token stack).
*/
- LinkedHashMap<String,Object> curToken = new LinkedHashMap<String,Object>();
+ LinkedHashMap<String, Object> curToken = new LinkedHashMap<String, Object>();
/**
- * Keeps track of operands lists that are to be serialised in an inverted
- * order (e.g. the IN() operator) compared to their AST representation.
+ * Keeps track of operands lists that are to be serialised in an
+ * inverted
+ * order (e.g. the IN() operator) compared to their AST
+ * representation.
*/
- private LinkedList<ArrayList<Object>> invertedOperandsLists =
- new LinkedList<ArrayList<Object>>();
+ private LinkedList<ArrayList<Object>> invertedOperandsLists = new LinkedList<ArrayList<Object>>();
/**
* Keeps track of operation:class numbers.
*/
int classCounter = 1;
/**
- * Keeps track of numers of relations processed (important when dealing
+ * Keeps track of numers of relations processed (important when
+ * dealing
* with multiple predications).
*/
int relationCounter = 0;
/**
- * Keeps track of references to nodes that are operands of groups (e.g.
- * tree relations). Those nodes appear on the top level of the parse tree
- * but are to be integrated into the AqlTree at a later point (namely as
- * operands of the respective group). Therefore, store references to these
- * nodes here and exclude the operands from being written into the query
- * map individually.
+ * Keeps track of references to nodes that are operands of groups
+ * (e.g.
+ * tree relations). Those nodes appear on the top level of the
+ * parse tree
+ * but are to be integrated into the AqlTree at a later point
+ * (namely as
+ * operands of the respective group). Therefore, store references
+ * to these
+ * nodes here and exclude the operands from being written into the
+ * query
+ * map individually.
*/
private int totalRelationCount = 0;
/**
- * Keeps a record of reference-class-mapping, i.e. which 'class' has been
- * assigned to which #n reference. This is important when introducing
- * koral:reference spans to refer back to previously established classes for
+ * Keeps a record of reference-class-mapping, i.e. which 'class'
+ * has been
+ * assigned to which #n reference. This is important when
+ * introducing
+ * koral:reference spans to refer back to previously established
+ * classes for
* entities.
*/
- private LinkedHashMap<String, Integer> refClassMapping =
- new LinkedHashMap<String, Integer>();
+ private LinkedHashMap<String, Integer> refClassMapping = new LinkedHashMap<String, Integer>();
/**
* Keeps a record of unary relations on spans/tokens.
*/
- private LinkedHashMap<String, ArrayList<ParseTree>> unaryRelations =
- new LinkedHashMap<String, ArrayList<ParseTree>>();
+ private LinkedHashMap<String, ArrayList<ParseTree>> unaryRelations = new LinkedHashMap<String, ArrayList<ParseTree>>();
/**
- * Keeps track of the number of references to a node/token by means of #n.
- * E.g. in the query <tt>tok="x" & tok="y" & tok="z" & #1 . #2 & #2 . #3</tt>,
+ * Keeps track of the number of references to a node/token by
+ * means of #n.
+ * E.g. in the query <tt>tok="x" & tok="y" & tok="z" & #1 . #2 &
+ * #2 . #3</tt>,
* the 2nd token ("y") is referenced twice, the others once.
*/
- private LinkedHashMap<String, Integer> nodeReferencesTotal =
- new LinkedHashMap<String, Integer>();
+ private LinkedHashMap<String, Integer> nodeReferencesTotal = new LinkedHashMap<String, Integer>();
/**
- * Keeps track of the number of references to a node/token that have
+ * Keeps track of the number of references to a node/token that
+ * have
* already been processed.
*/
- private LinkedHashMap<String, Integer> nodeReferencesProcessed =
- new LinkedHashMap<String, Integer>();
+ private LinkedHashMap<String, Integer> nodeReferencesProcessed = new LinkedHashMap<String, Integer>();
/**
- * Keeps track of queued relations. Relations sometimes cannot be processed
- * directly, namely in case it does not share any operands with the
- * previous relation. Then wait until a relation with a shared operand has
+ * Keeps track of queued relations. Relations sometimes cannot be
+ * processed
+ * directly, namely in case it does not share any operands with
+ * the
+ * previous relation. Then wait until a relation with a shared
+ * operand has
* been processed.
*/
private LinkedList<ParseTree> queuedRelations = new LinkedList<ParseTree>();
/**
- * For some objects, it may be decided in the initial scan
- * ({@link #processAndTopExpr(ParseTree)} that they need to be wrapped in a
- * class operation when retrieved later. This map stores this information.
- * More precisely, it stores for every node in the tree which class ID its
+ * For some objects, it may be decided in the initial scan
+ * ({@link #processAndTopExpr(ParseTree)} that they need to be
+ * wrapped in a
+ * class operation when retrieved later. This map stores this
+ * information.
+ * More precisely, it stores for every node in the tree which
+ * class ID its
* derived KoralQuery object will receive.
*/
- private LinkedHashMap<ParseTree, Integer> objectsToWrapInClass =
- new LinkedHashMap<ParseTree, Integer>();
+ private LinkedHashMap<ParseTree, Integer> objectsToWrapInClass = new LinkedHashMap<ParseTree, Integer>();
- public AnnisQueryProcessor(String query) {
+
+ public AnnisQueryProcessor (String query) {
KoralObjectGenerator.setQueryProcessor(this);
process(query);
}
+
@Override
- public void process(String query) {
+ public void process (String query) {
ParseTree tree = parseAnnisQuery(query);
if (this.parser != null) {
super.parser = this.parser;
- } else {
- throw new NullPointerException("Parser has not been instantiated!");
}
- log.info("Processing Annis query: "+query);
+ else {
+ throw new NullPointerException("Parser has not been instantiated!");
+ }
+ log.info("Processing Annis query: " + query);
if (tree != null) {
- log.debug("ANTLR parse tree: "+tree.toStringTree(parser));
+ log.debug("ANTLR parse tree: " + tree.toStringTree(parser));
processNode(tree);
// Last check to see if all relations have left the queue
if (!queuedRelations.isEmpty()) {
ParseTree queued = queuedRelations.pop();
- if (verbose) System.out.println("Taking off queue (last rel): "
- + queued.getText());
+ if (verbose)
+ System.out.println("Taking off queue (last rel): "
+ + queued.getText());
if (checkOperandsProcessedPreviously(queued)) {
processNode(queued);
- } else {
- addError(StatusCodes.UNBOUND_ANNIS_RELATION,
- "The relation " +queued.getText()+
- " is not bound to any other relations.");
- requestMap.put("query",
- new LinkedHashMap<String, Object>());
+ }
+ else {
+ addError(StatusCodes.UNBOUND_ANNIS_RELATION,
+ "The relation " + queued.getText()
+ + " is not bound to any other relations.");
+ requestMap
+ .put("query", new LinkedHashMap<String, Object>());
}
}
}
}
+
/**
- * Traverses the parse tree by recursively calling itself, starting with
- * the root node of the tree and calling itself with the children of its
- * current node in a depth-first, left-to-right fashion. In each call,
- * depending on the category of the current node, special processor
- * methods for the respective node category are called to process the node.
- * @param node The node currently visited in the parse tree traversal.
+ * Traverses the parse tree by recursively calling itself,
+ * starting with
+ * the root node of the tree and calling itself with the children
+ * of its
+ * current node in a depth-first, left-to-right fashion. In each
+ * call,
+ * depending on the category of the current node, special
+ * processor
+ * methods for the respective node category are called to process
+ * the node.
+ *
+ * @param node
+ * The node currently visited in the parse tree
+ * traversal.
*/
- private void processNode(ParseTree node) {
+ private void processNode (ParseTree node) {
String nodeCat = getNodeCat(node);
// Top-down processing
- if (visited.contains(node)) return;
+ if (visited.contains(node))
+ return;
openNodeCats.push(nodeCat);
stackedObjects = 0;
// Before doing anything else, check if any relations are queued
@@ -193,15 +231,16 @@
if (!queuedRelations.isEmpty()) {
ParseTree queued = queuedRelations.getFirst();
if (checkOperandsProcessedPreviously(queued)) {
- if (verbose) System.out.println("Taking off queue: "+
- queued.getText());
+ if (verbose)
+ System.out.println("Taking off queue: "
+ + queued.getText());
queuedRelations.removeFirst();
processNode(queued);
}
- }
+ }
}
if (verbose) {
- System.err.println(" "+objectStack);
+ System.err.println(" " + objectStack);
System.out.println(openNodeCats);
}
@@ -233,7 +272,7 @@
****************************************************************
****************************************************************
*/
- for (int i=0; i<node.getChildCount(); i++) {
+ for (int i = 0; i < node.getChildCount(); i++) {
ParseTree child = node.getChild(i);
processNode(child);
}
@@ -244,21 +283,26 @@
**************************************************************
*/
if (!objectsToPop.isEmpty()) {
- for (int i=0; i<objectsToPop.pop(); i++) {
- objectStack.pop();
+ for (int i = 0; i < objectsToPop.pop(); i++) {
+ objectStack.pop();
}
}
openNodeCats.pop();
}
+
/**
- * Processes an <tt>andTopExpr</tt> node. This is a child of the root
- * and contains a set of expressions connected by logical conjunction.
+ * Processes an <tt>andTopExpr</tt> node. This is a child of the
+ * root
+ * and contains a set of expressions connected by logical
+ * conjunction.
* Several of these nodes are possibly connected via disjunction.
- * @param node The current parse tree node (must be of category
- * <tt>andTopExpr</tt>).
+ *
+ * @param node
+ * The current parse tree node (must be of category
+ * <tt>andTopExpr</tt>).
*/
- private void processAndTopExpr(ParseTree node) {
+ private void processAndTopExpr (ParseTree node) {
// Before processing any child expr node, check if it has one or more
// "*ary_linguistic_term" nodes.
// Those nodes may use references to earlier established operand nodes.
@@ -266,52 +310,53 @@
// individually but naturally as operands of the relations/groups
// introduced by the node. For that purpose, this section mines all
// used references and stores them in a list for later reference.
- for (ParseTree unaryTermNode :
- getDescendantsWithCat(node, "unary_linguistic_term")) {
+ for (ParseTree unaryTermNode : getDescendantsWithCat(node,
+ "unary_linguistic_term")) {
String ref = getNodeCat(unaryTermNode.getChild(0)).substring(1);
ArrayList<ParseTree> unaryTermsForRef = unaryRelations.get(ref);
- if (unaryTermsForRef == null) unaryTermsForRef =
- new ArrayList<ParseTree>();
+ if (unaryTermsForRef == null)
+ unaryTermsForRef = new ArrayList<ParseTree>();
unaryTermsForRef.add(unaryTermNode);
unaryRelations.put(ref, unaryTermsForRef);
}
- for (ParseTree lingTermNode :
- getDescendantsWithCat(node, "n_ary_linguistic_term")) {
- for (ParseTree refOrNode :
- getChildrenWithCat(lingTermNode, "refOrNode")) {
- String refOrNodeString =
- refOrNode.getChild(0).toStringTree(parser);
+ for (ParseTree lingTermNode : getDescendantsWithCat(node,
+ "n_ary_linguistic_term")) {
+ for (ParseTree refOrNode : getChildrenWithCat(lingTermNode,
+ "refOrNode")) {
+ String refOrNodeString = refOrNode.getChild(0).toStringTree(
+ parser);
if (refOrNodeString.startsWith("#")) {
- String ref = refOrNode.getChild(0).toStringTree(parser).
- substring(1);
+ String ref = refOrNode.getChild(0).toStringTree(parser)
+ .substring(1);
if (nodeReferencesTotal.containsKey(ref)) {
- nodeReferencesTotal.put(ref,
- nodeReferencesTotal.get(ref)+1);
- } else {
+ nodeReferencesTotal.put(ref,
+ nodeReferencesTotal.get(ref) + 1);
+ }
+ else {
nodeReferencesTotal.put(ref, 1);
- nodeReferencesProcessed.put(ref, 0);
+ nodeReferencesProcessed.put(ref, 0);
}
}
}
totalRelationCount++;
}
// Then, mine all object definitions.
- for (ParseTree variableExprNode :
- getDescendantsWithCat(node, "variableExpr")) {
+ for (ParseTree variableExprNode : getDescendantsWithCat(node,
+ "variableExpr")) {
String ref;
// might be a ref label rather than a counting number
- ParseTree varDef =
- getFirstChildWithCat(variableExprNode.getParent(),"varDef");
+ ParseTree varDef = getFirstChildWithCat(
+ variableExprNode.getParent(), "varDef");
if (varDef != null) {
// remove trailing #
- ref = varDef.getText().replaceFirst("#", "");
- } else {
+ ref = varDef.getText().replaceFirst("#", "");
+ }
+ else {
ref = variableCount.toString();
}
nodes2refs.put(variableExprNode, ref);
- LinkedHashMap<String,Object> object =
- processVariableExpr(variableExprNode);
- nodeVariables.put(ref, object);
+ LinkedHashMap<String, Object> object = processVariableExpr(variableExprNode);
+ nodeVariables.put(ref, object);
variableCount++;
// Check if this object definition is part of a "direct declaration
// relation", i.e. a relation which declares its operands directly
@@ -319,90 +364,104 @@
// objects must still be available for later reference, handle this
// here. Direct declaration relation is present when grandparent is
// n_ary_linguistic_term node.
- if (getNodeCat(variableExprNode.getParent().getParent()).
- equals("n_ary_linguistic_term")) {
+ if (getNodeCat(variableExprNode.getParent().getParent()).equals(
+ "n_ary_linguistic_term")) {
if (nodeReferencesTotal.containsKey(ref)) {
- nodeReferencesTotal.put(ref,nodeReferencesTotal.get(ref)+1);
- } else {
+ nodeReferencesTotal.put(ref,
+ nodeReferencesTotal.get(ref) + 1);
+ }
+ else {
nodeReferencesTotal.put(ref, 1);
}
// This is important for later relations wrapping the present
// relation. If the object isn't registered as processed, it
// won't be available for referencing.
- nodeReferencesProcessed.put(ref, 1);
+ nodeReferencesProcessed.put(ref, 1);
// Register this node for latter wrapping in class.
if (nodeReferencesTotal.get(ref) > 1) {
- refClassMapping.put(ref, classCounter+128);
- objectsToWrapInClass.put(variableExprNode, 128+classCounter++);
+ refClassMapping.put(ref, classCounter + 128);
+ objectsToWrapInClass.put(variableExprNode,
+ 128 + classCounter++);
}
}
}
}
- private void processExprTop(ParseTree node) {
+
+ private void processExprTop (ParseTree node) {
List<ParseTree> andTopExprs = getChildrenWithCat(node, "andTopExpr");
if (andTopExprs.size() > 1) {
- LinkedHashMap<String, Object> topOr =
- KoralObjectGenerator.makeGroup("disjunction");
+ LinkedHashMap<String, Object> topOr = KoralObjectGenerator
+ .makeGroup("disjunction");
requestMap.put("query", topOr);
objectStack.push(topOr);
}
}
+
@SuppressWarnings("unchecked")
- private LinkedHashMap<String, Object> processVariableExpr(ParseTree node) {
+ private LinkedHashMap<String, Object> processVariableExpr (ParseTree node) {
// simplex word or complex assignment (like qname = textSpec)?
String firstChildNodeCat = getNodeCat(node.getChild(0));
LinkedHashMap<String, Object> object = null;
if (firstChildNodeCat.equals("node")) {
object = KoralObjectGenerator.makeSpan();
- } else if (firstChildNodeCat.equals("tok")) {
+ }
+ else if (firstChildNodeCat.equals("tok")) {
object = KoralObjectGenerator.makeToken();
if (node.getChildCount() > 1) { // empty tokens do not wrap a term
- LinkedHashMap<String, Object> term =
- KoralObjectGenerator.makeTerm();
+ LinkedHashMap<String, Object> term = KoralObjectGenerator
+ .makeTerm();
term.put("layer", "orth");
object.put("wrap", term);
}
- } else if (firstChildNodeCat.equals("qName")) {
+ }
+ else if (firstChildNodeCat.equals("qName")) {
// Only (foundry/)?layer specified.
// May be token or span, depending on indicated layer!
// (e.g. cnx/cat=NP vs mate/pos=NN)
// TODO generalize the list below -> look up layers associated with
// tokens rather than spans somewhere
- HashMap<String, Object> qNameParse =
- parseQNameNode(node.getChild(0));
- if (Arrays.asList(new String[]{"p", "lemma", "m", "orth"}).
- contains(qNameParse.get("layer"))) {
+ HashMap<String, Object> qNameParse = parseQNameNode(node
+ .getChild(0));
+ if (Arrays.asList(new String[] { "p", "lemma", "m", "orth" })
+ .contains(qNameParse.get("layer"))) {
object = KoralObjectGenerator.makeToken();
- LinkedHashMap<String, Object> term =
- KoralObjectGenerator.makeTerm();
+ LinkedHashMap<String, Object> term = KoralObjectGenerator
+ .makeTerm();
object.put("wrap", term);
term.putAll(qNameParse);
- } else {
+ }
+ else {
object = KoralObjectGenerator.makeSpan();
object.putAll(qNameParse);
}
- } else if (firstChildNodeCat.equals("textSpec")) {
+ }
+ else if (firstChildNodeCat.equals("textSpec")) {
object = KoralObjectGenerator.makeToken();
- LinkedHashMap<String, Object> term =
- KoralObjectGenerator.makeTerm();
+ LinkedHashMap<String, Object> term = KoralObjectGenerator
+ .makeTerm();
object.put("wrap", term);
term.put("layer", "orth");
term.putAll(parseTextSpec(node.getChild(0)));
}
- if (node.getChildCount() == 3) {
+ if (node.getChildCount() == 3) {
// (foundry/)?layer=key specification
if (object.get("@type").equals("koral:token")) {
- HashMap<String, Object> term = (HashMap<String, Object>)
- object.get("wrap");
+ HashMap<String, Object> term = (HashMap<String, Object>) object
+ .get("wrap");
term.putAll(parseTextSpec(node.getChild(2)));
- term.put("match", parseMatchOperator(
- getFirstChildWithCat(node, "eqOperator")));
- } else {
+ term.put(
+ "match",
+ parseMatchOperator(getFirstChildWithCat(node,
+ "eqOperator")));
+ }
+ else {
object.putAll(parseTextSpec(node.getChild(2)));
- object.put("match", parseMatchOperator(
- getFirstChildWithCat(node, "eqOperator")));
+ object.put(
+ "match",
+ parseMatchOperator(getFirstChildWithCat(node,
+ "eqOperator")));
}
}
@@ -412,13 +471,13 @@
if (unaryRelations.containsKey(ref)) {
ArrayList<ParseTree> unaryTermsForRef = unaryRelations.get(ref);
if (unaryTermsForRef.size() == 1) {
- object.put("attr",
- parseUnaryOperator(unaryTermsForRef.get(0)));
- } else {
- LinkedHashMap<String, Object> termGroup =
- KoralObjectGenerator.makeTermGroup("and");
- ArrayList<Object> operands = (ArrayList<Object>)
- termGroup.get("operands");
+ object.put("attr", parseUnaryOperator(unaryTermsForRef.get(0)));
+ }
+ else {
+ LinkedHashMap<String, Object> termGroup = KoralObjectGenerator
+ .makeTermGroup("and");
+ ArrayList<Object> operands = (ArrayList<Object>) termGroup
+ .get("operands");
for (ParseTree unaryTerm : unaryTermsForRef) {
operands.add(parseUnaryOperator(unaryTerm));
}
@@ -432,8 +491,9 @@
}
ParseTree parentsFirstChild = node.getParent().getChild(0);
if (getNodeCat(parentsFirstChild).endsWith("#")) {
- nodeVariables.put(getNodeCat(parentsFirstChild).
- replaceAll("#", ""), object);
+ nodeVariables.put(
+ getNodeCat(parentsFirstChild).replaceAll("#", ""),
+ object);
}
if (objectsToWrapInClass.containsKey(node)) {
int classId = objectsToWrapInClass.get(node);
@@ -443,66 +503,79 @@
return object;
}
+
/**
- * Processes an operand node, creating a map for the operand containing
- * all its information given in the node definition (referenced via '#').
- * If this node has been referred to and used earlier, a reference is
- * created in its place. The operand will be wrapped in a class group if
+ * Processes an operand node, creating a map for the operand
+ * containing
+ * all its information given in the node definition (referenced
+ * via '#').
+ * If this node has been referred to and used earlier, a reference
+ * is
+ * created in its place. The operand will be wrapped in a class
+ * group if
* necessary.
- * @param operandNode The operand node of a relation, e.g. '#1'
- * @return A map object with the appropriate KoralQuery representation
- * of the operand
+ *
+ * @param operandNode
+ * The operand node of a relation, e.g. '#1'
+ * @return A map object with the appropriate KoralQuery
+ * representation
+ * of the operand
*/
- private LinkedHashMap<String, Object> retrieveOperand(ParseTree operandNode) {
+ private LinkedHashMap<String, Object> retrieveOperand (ParseTree operandNode) {
LinkedHashMap<String, Object> operand = null;
if (!getNodeCat(operandNode.getChild(0)).equals("variableExpr")) {
- String ref =
- operandNode.getChild(0).toStringTree(parser).substring(1);
+ String ref = operandNode.getChild(0).toStringTree(parser)
+ .substring(1);
operand = nodeVariables.get(ref);
if (nodeReferencesTotal.get(ref) > 1) {
- if (nodeReferencesProcessed.get(ref)==0) {
- refClassMapping.put(ref, classCounter+128);
- operand = KoralObjectGenerator.
- wrapInClass(operand, 128+classCounter++);
- } else if (nodeReferencesProcessed.get(ref)>0 &&
- nodeReferencesTotal.get(ref)>1) {
+ if (nodeReferencesProcessed.get(ref) == 0) {
+ refClassMapping.put(ref, classCounter + 128);
+ operand = KoralObjectGenerator.wrapInClass(operand,
+ 128 + classCounter++);
+ }
+ else if (nodeReferencesProcessed.get(ref) > 0
+ && nodeReferencesTotal.get(ref) > 1) {
try {
operand = KoralObjectGenerator.wrapInReference(
operandStack.pop(), refClassMapping.get(ref));
- } catch (NoSuchElementException e) {
- operand = KoralObjectGenerator.makeReference(
- refClassMapping.get(ref));
+ }
+ catch (NoSuchElementException e) {
+ operand = KoralObjectGenerator
+ .makeReference(refClassMapping.get(ref));
}
}
- nodeReferencesProcessed.put(ref,
- nodeReferencesProcessed.get(ref)+1);
+ nodeReferencesProcessed.put(ref,
+ nodeReferencesProcessed.get(ref) + 1);
}
- } else {
+ }
+ else {
operand = processVariableExpr(operandNode.getChild(0));
}
return operand;
}
+
/**
* @param node
* @return
*/
- private boolean checkOperandsProcessedPreviously(ParseTree node) {
+ private boolean checkOperandsProcessedPreviously (ParseTree node) {
// We can assume two operands.
ParseTree operand1 = node.getChild(0);
ParseTree operand2 = node.getChild(2);
- if (checkOperandProcessedPreviously(operand1) ||
- checkOperandProcessedPreviously(operand2)) {
+ if (checkOperandProcessedPreviously(operand1)
+ || checkOperandProcessedPreviously(operand2)) {
return true;
}
return false;
}
+
/**
- * @param operand
+ * @param operand
* @return
*/
- private boolean checkOperandProcessedPreviously(ParseTree operand) {
+ private boolean checkOperandProcessedPreviously (ParseTree operand) {
String operandRef = operand.getText();
if (operandRef.startsWith("#")) {
operandRef = operandRef.substring(1, operandRef.length());
@@ -513,20 +586,21 @@
return false;
}
+
@SuppressWarnings("unchecked")
- private void processN_ary_linguistic_term(ParseTree node) {
+ private void processN_ary_linguistic_term (ParseTree node) {
relationCounter++;
// Get operator and determine type of group (sequence/treeRelation/
// relation/...). It's possible in Annis QL to concatenate operatiors,
// so there may be several operators under one n_ary_linguistic_term
// node. Counter 'i' will iteratively point to all operator nodes
// (odd-numbered children) under this node.
- for (int i=1; i<node.getChildCount(); i = i+2) {
- ParseTree operandTree1 = node.getChild(i-1);
- ParseTree operandTree2 = node.getChild(i+1);
+ for (int i = 1; i < node.getChildCount(); i = i + 2) {
+ ParseTree operandTree1 = node.getChild(i - 1);
+ ParseTree operandTree2 = node.getChild(i + 1);
String reltype = getNodeCat(node.getChild(i).getChild(0));
- LinkedHashMap<String,Object> group = null;
+ LinkedHashMap<String, Object> group = null;
ArrayList<Object> operands = null;
// make sure one of the operands has already been put into a
// relation (if this is not the 1st relation). If none of the
@@ -534,21 +608,20 @@
// unavailable for refrencing), queue this relation for later
// processing.
if (relationCounter != 1) {
- if (! checkOperandsProcessedPreviously(node)) {
+ if (!checkOperandsProcessedPreviously(node)) {
queuedRelations.add(node);
relationCounter--;
if (verbose) {
- System.out.println("Adding to queue: "+node.getText());
+ System.out
+ .println("Adding to queue: " + node.getText());
}
objectsToPop.push(stackedObjects);
return;
}
}
// Retrieve operands.
- LinkedHashMap<String, Object> operand1 =
- retrieveOperand(operandTree1);
- LinkedHashMap<String, Object> operand2 =
- retrieveOperand(operandTree2);
+ LinkedHashMap<String, Object> operand1 = retrieveOperand(operandTree1);
+ LinkedHashMap<String, Object> operand2 = retrieveOperand(operandTree2);
// 'Proper' n_ary_linguistic_operators receive a considerably
// different serialisation than 'commonparent' and 'commonancestor'
// For the latter cases, a dummy span is introduced and declared as
@@ -557,122 +630,132 @@
// relations! A Poliqarp+ equivalent for A $ B would be
// contains(focus(1:contains({1:<>},A)), B).
// This is modeled here...
- if (reltype.equals("commonparent") ||
- reltype.equals("commonancestor")) {
+ if (reltype.equals("commonparent")
+ || reltype.equals("commonancestor")) {
// make an (outer) group and an inner group containing the dummy
// node or previous relations
group = KoralObjectGenerator.makeGroup("relation");
- LinkedHashMap<String,Object> innerGroup =
- KoralObjectGenerator.makeGroup("relation");
- LinkedHashMap<String,Object> relation =
- KoralObjectGenerator.makeRelation();
- LinkedHashMap<String,Object> term =
- KoralObjectGenerator.makeTerm();
+ LinkedHashMap<String, Object> innerGroup = KoralObjectGenerator
+ .makeGroup("relation");
+ LinkedHashMap<String, Object> relation = KoralObjectGenerator
+ .makeRelation();
+ LinkedHashMap<String, Object> term = KoralObjectGenerator
+ .makeTerm();
term.put("layer", "c");
relation.put("wrap", term);
// commonancestor is an indirect commonparent relation
- if (reltype.equals("commonancestor")) relation.put("boundary",
- KoralObjectGenerator.makeBoundary(1, null));
+ if (reltype.equals("commonancestor"))
+ relation.put("boundary",
+ KoralObjectGenerator.makeBoundary(1, null));
group.put("relation", relation);
innerGroup.put("relation", relation);
// Get operands list before possible re-assignment of 'group'
// (see following 'if')
- ArrayList<Object> outerOperands =
- (ArrayList<Object>) group.get("operands");
- ArrayList<Object> innerOperands =
- (ArrayList<Object>) innerGroup.get("operands");
+ ArrayList<Object> outerOperands = (ArrayList<Object>) group
+ .get("operands");
+ ArrayList<Object> innerOperands = (ArrayList<Object>) innerGroup
+ .get("operands");
// for lowest level, add the underspecified node as first
// operand and wrap it in a class group
if (i == 1) {
- innerOperands.add(KoralObjectGenerator.wrapInClass(
- KoralObjectGenerator.makeSpan(), classCounter+128));
+ innerOperands
+ .add(KoralObjectGenerator.wrapInClass(
+ KoralObjectGenerator.makeSpan(),
+ classCounter + 128));
// add the first operand and wrap the whole group in a
// focusing reference
innerOperands.add(operand1);
- innerGroup = KoralObjectGenerator.
- wrapInReference(innerGroup, classCounter+128);
+ innerGroup = KoralObjectGenerator.wrapInReference(
+ innerGroup, classCounter + 128);
outerOperands.add(innerGroup);
- } else {
+ }
+ else {
outerOperands.add(operandStack.pop());
}
// Lookahead: if next operator is not commonparent or
// commonancestor, wrap in class for accessibility
- if (i < node.getChildCount()-2 && !getNodeCat(
- node.getChild(i+2).getChild(0)).startsWith("common")) {
- operand2 = KoralObjectGenerator.wrapInClass(
- operand2, ++classCounter+128);
+ if (i < node.getChildCount() - 2
+ && !getNodeCat(node.getChild(i + 2).getChild(0))
+ .startsWith("common")) {
+ operand2 = KoralObjectGenerator.wrapInClass(operand2,
+ ++classCounter + 128);
}
outerOperands.add(operand2);
// Wrap in another reference object in case other relations
// are following
- if (i < node.getChildCount()-2) {
- group = KoralObjectGenerator.wrapInReference(
- group, classCounter+128);
+ if (i < node.getChildCount() - 2) {
+ group = KoralObjectGenerator.wrapInReference(group,
+ classCounter + 128);
}
// All other n-ary linguistic relations have special 'relation'
// attributes defined in KoralQ. and can be handled more easily
- } else {
- LinkedHashMap<String, Object> operatorGroup =
- parseOperatorNode(node.getChild(i).getChild(0));
+ }
+ else {
+ LinkedHashMap<String, Object> operatorGroup = parseOperatorNode(node
+ .getChild(i).getChild(0));
String groupType;
try {
groupType = (String) operatorGroup.get("groupType");
- } catch (ClassCastException | NullPointerException n) {
+ }
+ catch (ClassCastException | NullPointerException n) {
groupType = "relation";
}
- if (groupType.equals("relation") ||
- groupType.equals("treeRelation")) {
+ if (groupType.equals("relation")
+ || groupType.equals("treeRelation")) {
group = KoralObjectGenerator.makeGroup(groupType);
- LinkedHashMap<String, Object> relation =
- new LinkedHashMap<String, Object>();
+ LinkedHashMap<String, Object> relation = new LinkedHashMap<String, Object>();
putAllButGroupType(relation, operatorGroup);
group.put("relation", relation);
- } else if (groupType.equals("sequence")) {
+ }
+ else if (groupType.equals("sequence")) {
group = KoralObjectGenerator.makeGroup(groupType);
putAllButGroupType(group, operatorGroup);
- } else if (groupType.equals("position")) {
- group = new LinkedHashMap<String,Object>();
+ }
+ else if (groupType.equals("position")) {
+ group = new LinkedHashMap<String, Object>();
putAllButGroupType(group, operatorGroup);
}
// Get operands list before possible re-assignment of 'group'
// (see following 'if')
- operands = (ArrayList<Object>) group.get("operands");
+ operands = (ArrayList<Object>) group.get("operands");
- ParseTree leftChildSpec = getFirstChildWithCat(
- node.getChild(i).getChild(0), "@l");
- ParseTree rightChildSpec = getFirstChildWithCat(
- node.getChild(i).getChild(0), "@r");
+ ParseTree leftChildSpec = getFirstChildWithCat(node.getChild(i)
+ .getChild(0), "@l");
+ ParseTree rightChildSpec = getFirstChildWithCat(node
+ .getChild(i).getChild(0), "@r");
if (leftChildSpec != null || rightChildSpec != null) {
- String frame = (leftChildSpec!=null) ?
- "frames:startsWith" : "frames:endsWith";
- LinkedHashMap<String,Object> positionGroup =
- KoralObjectGenerator.
- makePosition(new String[]{frame});
- operand2 = KoralObjectGenerator.wrapInClass(
- operand2, ++classCounter+128);
- ((ArrayList<Object>) positionGroup.get("operands")).
- add(group);
- ((ArrayList<Object>) positionGroup.get("operands")).
- add(KoralObjectGenerator.
- makeReference(classCounter+128));
+ String frame = (leftChildSpec != null) ? "frames:startsWith"
+ : "frames:endsWith";
+ LinkedHashMap<String, Object> positionGroup = KoralObjectGenerator
+ .makePosition(new String[] { frame });
+ operand2 = KoralObjectGenerator.wrapInClass(operand2,
+ ++classCounter + 128);
+ ((ArrayList<Object>) positionGroup.get("operands"))
+ .add(group);
+ ((ArrayList<Object>) positionGroup.get("operands"))
+ .add(KoralObjectGenerator
+ .makeReference(classCounter + 128));
group = positionGroup;
}
// Wrap in reference object in case other relations follow
- if (i < node.getChildCount()-2) {
- group = KoralObjectGenerator.wrapInReference(
- group, classCounter+128);
+ if (i < node.getChildCount() - 2) {
+ group = KoralObjectGenerator.wrapInReference(group,
+ classCounter + 128);
}
// Inject operands.
// -> Case distinction:
- if (node.getChildCount()==3) {
+ if (node.getChildCount() == 3) {
// Things are easy when there's just one operator
// (thus 3 children incl. operands)...
- if (operand1 != null) operands.add(operand1);
- if (operand2 != null) operands.add(operand2);
- } else {
+ if (operand1 != null)
+ operands.add(operand1);
+ if (operand2 != null)
+ operands.add(operand2);
+ }
+ else {
// ... but things get a little more complicated here. The
// AST is of this form: (operand1 operator1 operand2
// operator2 operand3 operator3 ...), but we'll have
@@ -681,67 +764,82 @@
// The following code will do just that:
if (i == 1) {
// for the first operator, include both operands
- if (operand1 != null) operands.add(operand1);
- if (operand2 != null) operands.add(KoralObjectGenerator.
- wrapInClass(operand2, 128+classCounter++));
+ if (operand1 != null)
+ operands.add(operand1);
+ if (operand2 != null)
+ operands.add(KoralObjectGenerator.wrapInClass(
+ operand2, 128 + classCounter++));
// Don't put this into the super object directly but
// store on operandStack (because this group will have
// to be an operand of a subsequent operator)
operandStack.push(group);
// for all subsequent operators, only take 2nd operand
// (1st was already added by previous operator)
- } else if (i < node.getChildCount()-2) {
+ }
+ else if (i < node.getChildCount() - 2) {
// for all intermediate operators, include other
// previous groups and 2nd operand. Store this on the
// operandStack, too.
- if (operand2 != null) operands.add(KoralObjectGenerator.
- wrapInClass(operand2, 128+classCounter++));
+ if (operand2 != null)
+ operands.add(KoralObjectGenerator.wrapInClass(
+ operand2, 128 + classCounter++));
operands.add(0, operandStack.pop());
operandStack.push(group);
- } else if (i == node.getChildCount()-2) {
+ }
+ else if (i == node.getChildCount() - 2) {
// This is the last operator. Include 2nd operand only
- if (operand2 != null) operands.add(operand2);
+ if (operand2 != null)
+ operands.add(operand2);
}
}
}
// Final step: decide what to do with the 'group' object, depending
// on whether all relations have been processed
- if (i == node.getChildCount()-2 &&
- relationCounter == totalRelationCount) {
+ if (i == node.getChildCount() - 2
+ && relationCounter == totalRelationCount) {
putIntoSuperObject(group);
if (!operandStack.isEmpty()) {
operands.add(0, operandStack.pop());
}
objectStack.push(group);
stackedObjects++;
- } else {
+ }
+ else {
operandStack.push(group);
}
}
}
+
/**
- * Parses a unary_linguistic_operator node. Possible operators are:
- * root, arity, tokenarity. Operators are embedded into a koral:term,
+ * Parses a unary_linguistic_operator node. Possible operators
+ * are:
+ * root, arity, tokenarity. Operators are embedded into a
+ * koral:term,
* in turn wrapped by an 'attr' property in a koral:span.
- * @param node The unary_linguistic_operator node
- * @return A map containing the attr key, to be inserted into koral:span
+ *
+ * @param node
+ * The unary_linguistic_operator node
+ * @return A map containing the attr key, to be inserted into
+ * koral:span
*/
- private LinkedHashMap<String, Object> parseUnaryOperator(ParseTree node) {
+ private LinkedHashMap<String, Object> parseUnaryOperator (ParseTree node) {
LinkedHashMap<String, Object> term = KoralObjectGenerator.makeTerm();
String op = node.getChild(1).toStringTree(parser).substring(1);
if (op.equals("arity") || op.equals("tokenarity")) {
- LinkedHashMap<String, Object> boundary =
- boundaryFromRangeSpec(node.getChild(3), false);
+ LinkedHashMap<String, Object> boundary = boundaryFromRangeSpec(
+ node.getChild(3), false);
term.put(op, boundary);
- } else {
+ }
+ else {
term.put(op, true);
}
return term;
}
+
@SuppressWarnings("unchecked")
- private LinkedHashMap<String, Object> parseOperatorNode(
+ private LinkedHashMap<String, Object> parseOperatorNode (
ParseTree operatorNode) {
LinkedHashMap<String, Object> relation = null;
String operator = getNodeCat(operatorNode);
@@ -749,68 +847,72 @@
if (operator.equals("dominance")) {
relation = KoralObjectGenerator.makeRelation();
relation.put("groupType", "relation");
- ParseTree qName = getFirstChildWithCat(
- operatorNode, "qName");
- ParseTree edgeSpecNode = getFirstChildWithCat(
- operatorNode, "edgeSpec");
+ ParseTree qName = getFirstChildWithCat(operatorNode, "qName");
+ ParseTree edgeSpecNode = getFirstChildWithCat(operatorNode,
+ "edgeSpec");
ParseTree star = getFirstChildWithCat(operatorNode, "*");
- ParseTree rangeSpec = getFirstChildWithCat(
- operatorNode, "rangeSpec");
- LinkedHashMap<String,Object> term= KoralObjectGenerator.makeTerm();
+ ParseTree rangeSpec = getFirstChildWithCat(operatorNode,
+ "rangeSpec");
+ LinkedHashMap<String, Object> term = KoralObjectGenerator
+ .makeTerm();
term.put("layer", "c");
- if (qName != null) term = parseQNameNode(qName);
+ if (qName != null)
+ term = parseQNameNode(qName);
if (edgeSpecNode != null) {
- LinkedHashMap<String,Object> edgeSpec =
- parseEdgeSpec(edgeSpecNode);
+ LinkedHashMap<String, Object> edgeSpec = parseEdgeSpec(edgeSpecNode);
String edgeSpecType = (String) edgeSpec.get("@type");
if (edgeSpecType.equals("koral:termGroup")) {
((ArrayList<Object>) edgeSpec.get("operands")).add(term);
term = edgeSpec;
- } else {
+ }
+ else {
term = KoralObjectGenerator.makeTermGroup("and");
- ArrayList<Object> termGroupOperands =
- (ArrayList<Object>) term.get("operands");
+ ArrayList<Object> termGroupOperands = (ArrayList<Object>) term
+ .get("operands");
termGroupOperands.add(edgeSpec);
- LinkedHashMap<String,Object> constTerm =
- KoralObjectGenerator.makeTerm();
+ LinkedHashMap<String, Object> constTerm = KoralObjectGenerator
+ .makeTerm();
constTerm.put("layer", "c");
termGroupOperands.add(constTerm);
}
}
- if (star != null) relation.put("boundary",
- KoralObjectGenerator.makeBoundary(0, null));
- if (rangeSpec != null) relation.put("boundary",
- boundaryFromRangeSpec(rangeSpec));
+ if (star != null)
+ relation.put("boundary",
+ KoralObjectGenerator.makeBoundary(0, null));
+ if (rangeSpec != null)
+ relation.put("boundary", boundaryFromRangeSpec(rangeSpec));
relation.put("wrap", term);
}
else if (operator.equals("pointing")) {
relation = KoralObjectGenerator.makeRelation();
relation.put("groupType", "relation");
ParseTree qName = getFirstChildWithCat(operatorNode, "qName");
- ParseTree edgeSpec =
- getFirstChildWithCat(operatorNode, "edgeSpec");
+ ParseTree edgeSpec = getFirstChildWithCat(operatorNode, "edgeSpec");
ParseTree star = getFirstChildWithCat(operatorNode, "*");
- ParseTree rangeSpec =
- getFirstChildWithCat(operatorNode, "rangeSpec");
- LinkedHashMap<String,Object> term= KoralObjectGenerator.makeTerm();
- if (qName != null) term.putAll(parseQNameNode(qName));
- if (edgeSpec != null) term.putAll(parseEdgeSpec(edgeSpec));
- if (star != null) relation.put("boundary",
- KoralObjectGenerator.makeBoundary(0, null));
- if (rangeSpec != null) relation.put("boundary",
- boundaryFromRangeSpec(rangeSpec));
+ ParseTree rangeSpec = getFirstChildWithCat(operatorNode,
+ "rangeSpec");
+ LinkedHashMap<String, Object> term = KoralObjectGenerator
+ .makeTerm();
+ if (qName != null)
+ term.putAll(parseQNameNode(qName));
+ if (edgeSpec != null)
+ term.putAll(parseEdgeSpec(edgeSpec));
+ if (star != null)
+ relation.put("boundary",
+ KoralObjectGenerator.makeBoundary(0, null));
+ if (rangeSpec != null)
+ relation.put("boundary", boundaryFromRangeSpec(rangeSpec));
relation.put("wrap", term);
}
else if (operator.equals("precedence")) {
relation = new LinkedHashMap<String, Object>();
relation.put("groupType", "sequence");
- ParseTree rangeSpec =
- getFirstChildWithCat(operatorNode, "rangeSpec");
+ ParseTree rangeSpec = getFirstChildWithCat(operatorNode,
+ "rangeSpec");
ParseTree star = getFirstChildWithCat(operatorNode, "*");
ArrayList<Object> distances = new ArrayList<Object>();
if (star != null) {
- distances.add(KoralObjectGenerator.
- makeDistance("w", 0, null));
+ distances.add(KoralObjectGenerator.makeDistance("w", 0, null));
relation.put("distances", distances);
}
if (rangeSpec != null) {
@@ -821,46 +923,44 @@
}
else if (operator.equals("spanrelation")) {
String reltype = operatorNode.getChild(0).toStringTree(parser);
- String[] frames = new String[]{};
+ String[] frames = new String[] {};
switch (reltype) {
case "_=_":
- frames = new String[]{"frames:matches"};
+ frames = new String[] { "frames:matches" };
break;
case "_l_":
- frames = new String[]{"frames:startsWith",
- "frames:matches"};
+ frames = new String[] { "frames:startsWith",
+ "frames:matches" };
break;
case "_r_":
- frames = new String[]{"frames:endsWith",
- "frames:matches"};
+ frames = new String[] { "frames:endsWith", "frames:matches" };
break;
case "_i_":
- frames = new String[]{"frames:isAround"};
+ frames = new String[] { "frames:isAround" };
break;
case "_o_":
- frames = new String[]{"frames:overlapsLeft",
- "frames:overlapsRight"};
+ frames = new String[] { "frames:overlapsLeft",
+ "frames:overlapsRight" };
break;
case "_ol_":
- frames = new String[]{"frames:overlapsLeft"};
+ frames = new String[] { "frames:overlapsLeft" };
break;
case "_or_":
- frames = new String[]{"frames:overlapsRight"};
+ frames = new String[] { "frames:overlapsRight" };
break;
}
relation = KoralObjectGenerator.makePosition(frames);
relation.put("groupType", "position");
- }
+ }
else if (operator.equals("near")) {
relation = new LinkedHashMap<String, Object>();
relation.put("groupType", "sequence");
- ParseTree rangeSpec =
- getFirstChildWithCat(operatorNode, "rangeSpec");
+ ParseTree rangeSpec = getFirstChildWithCat(operatorNode,
+ "rangeSpec");
ParseTree star = getFirstChildWithCat(operatorNode, "*");
ArrayList<Object> distances = new ArrayList<Object>();
if (star != null) {
- distances.add(KoralObjectGenerator.
- makeDistance("w", 0, null));
+ distances.add(KoralObjectGenerator.makeDistance("w", 0, null));
relation.put("distances", distances);
}
if (rangeSpec != null) {
@@ -881,15 +981,17 @@
return relation;
}
+
@SuppressWarnings("unchecked")
- private LinkedHashMap<String,Object> parseEdgeSpec(ParseTree edgeSpec) {
+ private LinkedHashMap<String, Object> parseEdgeSpec (ParseTree edgeSpec) {
List<ParseTree> annos = getChildrenWithCat(edgeSpec, "edgeAnno");
- if (annos.size() == 1) return parseEdgeAnno(annos.get(0));
+ if (annos.size() == 1)
+ return parseEdgeAnno(annos.get(0));
else {
- LinkedHashMap<String,Object> termGroup =
- KoralObjectGenerator.makeTermGroup("and");
- ArrayList<Object> operands =
- (ArrayList<Object>) termGroup.get("operands");
+ LinkedHashMap<String, Object> termGroup = KoralObjectGenerator
+ .makeTermGroup("and");
+ ArrayList<Object> operands = (ArrayList<Object>) termGroup
+ .get("operands");
for (ParseTree anno : annos) {
operands.add(parseEdgeAnno(anno));
}
@@ -897,42 +999,46 @@
}
}
- private LinkedHashMap<String, Object> parseEdgeAnno(
- ParseTree edgeAnnoSpec) {
- LinkedHashMap<String, Object> edgeAnno =
- KoralObjectGenerator.makeTerm();
- ParseTree textSpecNode= getFirstChildWithCat(edgeAnnoSpec, "textSpec");
+
+ private LinkedHashMap<String, Object> parseEdgeAnno (ParseTree edgeAnnoSpec) {
+ LinkedHashMap<String, Object> edgeAnno = KoralObjectGenerator
+ .makeTerm();
+ ParseTree textSpecNode = getFirstChildWithCat(edgeAnnoSpec, "textSpec");
ParseTree layerNode = getFirstChildWithCat(edgeAnnoSpec, "layer");
ParseTree foundryNode = getFirstChildWithCat(edgeAnnoSpec, "foundry");
- ParseTree matchOperatorNode =
- getFirstChildWithCat(edgeAnnoSpec, "eqOperator");
- if (foundryNode!=null) edgeAnno.put("foundry",
- foundryNode.getChild(0).toStringTree(parser));
- if (layerNode!=null) edgeAnno.put("layer",
- layerNode.getChild(0).toStringTree(parser));
+ ParseTree matchOperatorNode = getFirstChildWithCat(edgeAnnoSpec,
+ "eqOperator");
+ if (foundryNode != null)
+ edgeAnno.put("foundry", foundryNode.getChild(0)
+ .toStringTree(parser));
+ if (layerNode != null)
+ edgeAnno.put("layer", layerNode.getChild(0).toStringTree(parser));
edgeAnno.putAll(parseTextSpec(textSpecNode));
edgeAnno.put("match", parseMatchOperator(matchOperatorNode));
return edgeAnno;
}
- private LinkedHashMap<String, Object> boundaryFromRangeSpec(
+
+ private LinkedHashMap<String, Object> boundaryFromRangeSpec (
ParseTree rangeSpec) {
- return boundaryFromRangeSpec(rangeSpec, true);
+ return boundaryFromRangeSpec(rangeSpec, true);
}
- private LinkedHashMap<String, Object> boundaryFromRangeSpec(
+
+ private LinkedHashMap<String, Object> boundaryFromRangeSpec (
ParseTree rangeSpec, boolean expandToMax) {
- Integer min = Integer.parseInt(
- rangeSpec.getChild(0).toStringTree(parser));
+ Integer min = Integer.parseInt(rangeSpec.getChild(0).toStringTree(
+ parser));
Integer max = min;
- if (expandToMax) max = null;
- if (rangeSpec.getChildCount()==3)
- max = Integer.parseInt(
- rangeSpec.getChild(2).toStringTree(parser));
+ if (expandToMax)
+ max = null;
+ if (rangeSpec.getChildCount() == 3)
+ max = Integer.parseInt(rangeSpec.getChild(2).toStringTree(parser));
return KoralObjectGenerator.makeBoundary(min, max);
}
- private LinkedHashMap<String, Object> parseDistance(ParseTree rangeSpec) {
+
+ private LinkedHashMap<String, Object> parseDistance (ParseTree rangeSpec) {
String minString = rangeSpec.getChild(0).toStringTree(parser);
String maxString = null; // not always given, prevent NPE
if (minString.equals("0")) {
@@ -941,77 +1047,88 @@
}
// decrease by 1 to account for disparity between ANNIS distance and
// koral:distance (ANNIS "x .1,3 y" means distance range 0,2 in KoralQ)
- Integer min = Integer.parseInt(minString)-1;
+ Integer min = Integer.parseInt(minString) - 1;
Integer max = null;
if (rangeSpec.getChildCount() == 3) {
maxString = rangeSpec.getChild(2).toStringTree(parser);
- max = Integer.parseInt(maxString)-1;
+ max = Integer.parseInt(maxString) - 1;
}
return KoralObjectGenerator.makeDistance("w", min, max);
}
- private LinkedHashMap<String, Object> parseTextSpec(ParseTree node) {
+
+ private LinkedHashMap<String, Object> parseTextSpec (ParseTree node) {
LinkedHashMap<String, Object> term = new LinkedHashMap<String, Object>();
if (hasChild(node, "regex")) {
term.put("type", "type:regex");
- term.put("key", node.getChild(0).getChild(0).toStringTree(parser).
- replaceAll("/", ""));
- } else {
+ term.put("key", node.getChild(0).getChild(0).toStringTree(parser)
+ .replaceAll("/", ""));
+ }
+ else {
term.put("key", node.getChild(1).toStringTree(parser));
}
term.put("match", "match:eq");
return term;
}
+
/**
* Parses the match operator (= or !=)
+ *
* @param node
* @return
*/
- private String parseMatchOperator(ParseTree node) {
- if (node.getChildCount()>0) {
- return node.getChild(0).getText().equals("=") ?
- "match:eq" : "match:ne";
+ private String parseMatchOperator (ParseTree node) {
+ if (node.getChildCount() > 0) {
+ return node.getChild(0).getText().equals("=") ? "match:eq"
+ : "match:ne";
}
return "match:eq";
}
- private LinkedHashMap<String, Object> parseQNameNode(ParseTree node) {
- LinkedHashMap<String, Object> fields =
- new LinkedHashMap<String, Object>();
+
+ private LinkedHashMap<String, Object> parseQNameNode (ParseTree node) {
+ LinkedHashMap<String, Object> fields = new LinkedHashMap<String, Object>();
ParseTree layerNode = getFirstChildWithCat(node, "layer");
ParseTree foundryNode = getFirstChildWithCat(node, "foundry");
- if (foundryNode != null) fields.put("foundry",
- foundryNode.getChild(0).toStringTree(parser));
+ if (foundryNode != null)
+ fields.put("foundry", foundryNode.getChild(0).toStringTree(parser));
String layer = layerNode.getChild(0).toStringTree(parser);
- if (layer.equals("pos")) layer = "p";
- if (layer.equals("cat")) layer = "c";
+ if (layer.equals("pos"))
+ layer = "p";
+ if (layer.equals("cat"))
+ layer = "c";
fields.put("layer", layer);
return fields;
}
- private void putIntoSuperObject(LinkedHashMap<String, Object> object) {
+
+ private void putIntoSuperObject (LinkedHashMap<String, Object> object) {
putIntoSuperObject(object, 0);
}
+
@SuppressWarnings({ "unchecked" })
- private void putIntoSuperObject(
- LinkedHashMap<String, Object> object, int objStackPosition) {
- if (objectStack.size()>objStackPosition) {
- ArrayList<Object> topObjectOperands = (ArrayList<Object>)
- objectStack.get(objStackPosition).get("operands");
+ private void putIntoSuperObject (LinkedHashMap<String, Object> object,
+ int objStackPosition) {
+ if (objectStack.size() > objStackPosition) {
+ ArrayList<Object> topObjectOperands = (ArrayList<Object>) objectStack
+ .get(objStackPosition).get("operands");
if (!invertedOperandsLists.contains(topObjectOperands)) {
topObjectOperands.add(object);
- } else {
+ }
+ else {
topObjectOperands.add(0, object);
}
- } else {
+ }
+ else {
requestMap.put("query", object);
}
}
- private void putAllButGroupType(
- Map<String, Object> container, Map<String, Object> input) {
+
+ private void putAllButGroupType (Map<String, Object> container,
+ Map<String, Object> input) {
for (String key : input.keySet()) {
if (!key.equals("groupType")) {
container.put(key, input.get(key));
@@ -1019,11 +1136,12 @@
}
}
+
private ParserRuleContext parseAnnisQuery (String query) {
- Lexer lexer = new AqlLexer((CharStream)null);
+ Lexer lexer = new AqlLexer((CharStream) null);
ParserRuleContext tree = null;
- Antlr4DescriptiveErrorListener errorListener =
- new Antlr4DescriptiveErrorListener(query);
+ Antlr4DescriptiveErrorListener errorListener = new Antlr4DescriptiveErrorListener(
+ query);
// Like p. 111
try {
// Tokenize input data
@@ -1038,8 +1156,9 @@
parser.removeErrorListeners();
parser.addErrorListener(errorListener);
// Get starting rule from parser
- Method startRule = AqlParser.class.getMethod("start");
- tree = (ParserRuleContext)startRule.invoke(parser, (Object[])null);
+ Method startRule = AqlParser.class.getMethod("start");
+ tree = (ParserRuleContext) startRule
+ .invoke(parser, (Object[]) null);
}
// Some things went wrong ...
catch (Exception e) {
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/Antlr3AbstractQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/Antlr3AbstractQueryProcessor.java
index 9b86e69..e6b2d59 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/Antlr3AbstractQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/Antlr3AbstractQueryProcessor.java
@@ -9,11 +9,15 @@
import org.antlr.runtime.tree.Tree;
/**
- * This class is provides methods for navigation and search in Abstract Syntax
- * Trees returned by ANTLR v3 parsers, using ANTLR v3 libraries. Any class that
- * extends this abstract class will thus be equipped with such methods,
- * which makes it easier to, e.g., retrieve children of a specific category
- * for some node.
+ * This class is provides methods for navigation and search in
+ * Abstract Syntax
+ * Trees returned by ANTLR v3 parsers, using ANTLR v3 libraries. Any
+ * class that
+ * extends this abstract class will thus be equipped with such
+ * methods,
+ * which makes it easier to, e.g., retrieve children of a specific
+ * category
+ * for some node.
*
* @author Joachim Bingel (bingel@ids-mannheim.de)
* @version 0.3.0
@@ -27,17 +31,19 @@
*/
protected Parser parser;
+
/**
* Returns the category (or 'label') of the root of a (sub-)
* ParseTree (ANTLR 3).
- *
- * @param node The tree node.
+ *
+ * @param node
+ * The tree node.
* @return The category of the node.
*/
- protected static String getNodeCat(Tree node) {
+ protected static String getNodeCat (Tree node) {
String nodeCat = node.toStringTree();
// from opening parenthesis to 1st whitespace
- Pattern p = Pattern.compile("\\((.*?)\\s");
+ Pattern p = Pattern.compile("\\((.*?)\\s");
Matcher m = p.matcher(node.toStringTree());
if (m.find()) {
nodeCat = m.group(1);
@@ -45,9 +51,10 @@
return nodeCat;
}
+
/**
* Tests whether a certain node has a child of a certain category.
- *
+ *
* @param node
* The parent node.
* @param childCat
@@ -55,7 +62,7 @@
* @return true iff one or more children belong to the specified
* category.
*/
- protected static boolean hasChild(Tree node, String childCat) {
+ protected static boolean hasChild (Tree node, String childCat) {
for (int i = 0; i < node.getChildCount(); i++) {
if (getNodeCat(node.getChild(i)).equals(childCat)) {
return true;
@@ -64,18 +71,21 @@
return false;
}
+
/**
- * Tests whether a certain node has a descendant (direct or indirect child)
+ * Tests whether a certain node has a descendant (direct or
+ * indirect child)
* of a certain category.
- *
+ *
* @param node
* The parent node.
* @param childCat
* The category of the potential descendant.
- * @return true iff one or more descendants belong to the specified
+ * @return true iff one or more descendants belong to the
+ * specified
* category.
*/
- protected static boolean hasDescendantWithCat(Tree node, String childCat) {
+ protected static boolean hasDescendantWithCat (Tree node, String childCat) {
for (int i = 0; i < node.getChildCount(); i++) {
Tree child = node.getChild(i);
if (getNodeCat(child).equals(childCat)) {
@@ -88,12 +98,15 @@
return false;
}
+
/**
* Returns all children of a node.
- * @param node The node.
- * @return A list containing all children.
+ *
+ * @param node
+ * The node.
+ * @return A list containing all children.
*/
- protected static List<Tree> getChildren(Tree node) {
+ protected static List<Tree> getChildren (Tree node) {
ArrayList<Tree> children = new ArrayList<Tree>();
for (int i = 0; i < node.getChildCount(); i++) {
children.add(node.getChild(i));
@@ -101,14 +114,20 @@
return children;
}
+
/**
* Returns all children of a node which are of a given category.
- * @param node The node.
- * @param nodeCat The node category constraining the returned children.
- * @return A (possibly empty) list containing all children of the given
- * category.
+ *
+ * @param node
+ * The node.
+ * @param nodeCat
+ * The node category constraining the returned
+ * children.
+ * @return A (possibly empty) list containing all children of the
+ * given
+ * category.
*/
- protected static List<Tree> getChildrenWithCat(Tree node, String nodeCat) {
+ protected static List<Tree> getChildrenWithCat (Tree node, String nodeCat) {
ArrayList<Tree> children = new ArrayList<Tree>();
for (int i = 0; i < node.getChildCount(); i++) {
if (getNodeCat(node.getChild(i)).equals(nodeCat)) {
@@ -118,15 +137,22 @@
return children;
}
+
/**
- * Returns all descendants (direct or indirect children) of a node which
+ * Returns all descendants (direct or indirect children) of a node
+ * which
* are of a given category.
- * @param node The node.
- * @param nodeCat The node category constraining the returned descendants.
- * @return A (possibly empty) list containing all descendants of the given
- * category.
+ *
+ * @param node
+ * The node.
+ * @param nodeCat
+ * The node category constraining the returned
+ * descendants.
+ * @return A (possibly empty) list containing all descendants of
+ * the given
+ * category.
*/
- protected List<Tree> getDescendantsWithCat(Tree node, String nodeCat) {
+ protected List<Tree> getDescendantsWithCat (Tree node, String nodeCat) {
ArrayList<Tree> descendants = new ArrayList<Tree>();
for (Tree child : getChildren(node)) {
if (getNodeCat(child).equals(nodeCat)) {
@@ -136,29 +162,42 @@
}
return descendants;
}
-
+
+
/**
* Returns the first child of a node which is of a given category.
- * @param node The node.
- * @param nodeCat The node category constraining the returned child.
- * @return The first child with the given category, <tt>null</tt> if no
- * such child exists.
+ *
+ * @param node
+ * The node.
+ * @param nodeCat
+ * The node category constraining the returned child.
+ * @return The first child with the given category, <tt>null</tt>
+ * if no
+ * such child exists.
*/
- protected static Tree getFirstChildWithCat(Tree node, String nodeCat) {
+ protected static Tree getFirstChildWithCat (Tree node, String nodeCat) {
return getNthChildWithCat(node, nodeCat, 1);
}
+
/**
* Returns the nth child of a node which is of a given category.
- * @param node The node.
- * @param nodeCat The node category constraining the returned child.
- * @param n The index of the child to return, among all children with the
- * given category.
- * @return The nth child with the given category, <tt>null</tt> if no
- * such child exists (i.e., if n is larger than the number of children
- * with the given category).
+ *
+ * @param node
+ * The node.
+ * @param nodeCat
+ * The node category constraining the returned child.
+ * @param n
+ * The index of the child to return, among all children
+ * with the
+ * given category.
+ * @return The nth child with the given category, <tt>null</tt> if
+ * no
+ * such child exists (i.e., if n is larger than the number
+ * of children
+ * with the given category).
*/
- protected static Tree getNthChildWithCat(Tree node,String nodeCat, int n) {
+ protected static Tree getNthChildWithCat (Tree node, String nodeCat, int n) {
int counter = 0;
for (int i = 0; i < node.getChildCount(); i++) {
if (getNodeCat(node.getChild(i)).equals(nodeCat)) {
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/Antlr4AbstractQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/Antlr4AbstractQueryProcessor.java
index d22c8b3..042b177 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/Antlr4AbstractQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/Antlr4AbstractQueryProcessor.java
@@ -9,46 +9,54 @@
import org.antlr.v4.runtime.tree.ParseTree;
/**
- * This class is provides methods for navigation and search in Abstract Syntax
- * Trees returned by ANTLR v4 parsers, using ANTLR v4 libraries. Any class that
- * extends this abstract class will thus be equipped with such methods,
- * which makes it easier to, e.g., retrieve children of a specific category
- * for some node.
+ * This class is provides methods for navigation and search in
+ * Abstract Syntax
+ * Trees returned by ANTLR v4 parsers, using ANTLR v4 libraries. Any
+ * class that
+ * extends this abstract class will thus be equipped with such
+ * methods,
+ * which makes it easier to, e.g., retrieve children of a specific
+ * category
+ * for some node.
*
* @author Joachim Bingel (bingel@ids-mannheim.de)
* @version 0.3.0
* @since 0.1.0
*/
-public abstract class Antlr4AbstractQueryProcessor extends
+public abstract class Antlr4AbstractQueryProcessor extends
AbstractQueryProcessor {
/**
- * The ANTLR parser. Subclasses need to instantiate this field such that it
+ * The ANTLR parser. Subclasses need to instantiate this field
+ * such that it
* can be used in the methods of this class.
*/
- protected Parser parser;
+ protected Parser parser;
- /**
- * Returns the category (or 'label') of the root of a (sub-)
+
+ /**
+ * Returns the category (or 'label') of the root of a (sub-)
* ParseTree (ANTLR 4).
- *
- * @param node The tree node.
+ *
+ * @param node
+ * The tree node.
* @return The category of the node.
*/
- protected String getNodeCat(ParseTree node) {
+ protected String getNodeCat (ParseTree node) {
String nodeCat = node.toStringTree(parser);
// pattern: from opening parenthesis to 1st whitespace
- Pattern p = Pattern.compile("\\((.*?)\\s");
+ Pattern p = Pattern.compile("\\((.*?)\\s");
Matcher m = p.matcher(node.toStringTree(parser));
if (m.find()) {
nodeCat = m.group(1);
}
return nodeCat;
}
-
- /**
+
+
+ /**
* Tests whether a certain node has a child of a certain category.
- *
+ *
* @param node
* The parent node.
* @param childCat
@@ -56,7 +64,7 @@
* @return true iff one or more children belong to the specified
* category.
*/
- protected boolean hasChild(ParseTree node, String childCat) {
+ protected boolean hasChild (ParseTree node, String childCat) {
for (int i = 0; i < node.getChildCount(); i++) {
if (getNodeCat(node.getChild(i)).equals(childCat)) {
return true;
@@ -65,18 +73,21 @@
return false;
}
+
/**
- * Tests whether a certain node has a descendant (direct or indirect child)
+ * Tests whether a certain node has a descendant (direct or
+ * indirect child)
* of a certain category.
- *
+ *
* @param node
* The parent node.
* @param childCat
* The category of the potential descendant.
- * @return true iff one or more descendants belong to the specified
+ * @return true iff one or more descendants belong to the
+ * specified
* category.
*/
- protected boolean hasDescendantWithCat(ParseTree node, String childCat) {
+ protected boolean hasDescendantWithCat (ParseTree node, String childCat) {
for (int i = 0; i < node.getChildCount(); i++) {
ParseTree child = node.getChild(i);
if (getNodeCat(child).equals(childCat)) {
@@ -88,29 +99,37 @@
}
return false;
}
-
+
+
/**
* Returns all children of a node.
- * @param node The node.
- * @return A list containing all children.
+ *
+ * @param node
+ * The node.
+ * @return A list containing all children.
*/
- protected List<ParseTree> getChildren(ParseTree node) {
+ protected List<ParseTree> getChildren (ParseTree node) {
ArrayList<ParseTree> children = new ArrayList<ParseTree>();
for (int i = 0; i < node.getChildCount(); i++) {
- children.add(node.getChild(i));
+ children.add(node.getChild(i));
}
return children;
}
-
+
+
/**
* Returns all children of a node which are of a given category.
- * @param node The node.
- * @param nodeCat The node category constraining the returned children.
- * @return A (possibly empty) list containing all children of the given
- * category.
+ *
+ * @param node
+ * The node.
+ * @param nodeCat
+ * The node category constraining the returned
+ * children.
+ * @return A (possibly empty) list containing all children of the
+ * given
+ * category.
*/
- protected List<ParseTree> getChildrenWithCat(ParseTree node,
- String nodeCat) {
+ protected List<ParseTree> getChildrenWithCat (ParseTree node, String nodeCat) {
ArrayList<ParseTree> children = new ArrayList<ParseTree>();
for (int i = 0; i < node.getChildCount(); i++) {
if (getNodeCat(node.getChild(i)).equals(nodeCat)) {
@@ -119,16 +138,23 @@
}
return children;
}
-
+
+
/**
- * Returns all descendants (direct or indirect children) of a node which
+ * Returns all descendants (direct or indirect children) of a node
+ * which
* are of a given category.
- * @param node The node.
- * @param nodeCat The node category constraining the returned descendants.
- * @return A (possibly empty) list containing all descendants of the given
- * category.
+ *
+ * @param node
+ * The node.
+ * @param nodeCat
+ * The node category constraining the returned
+ * descendants.
+ * @return A (possibly empty) list containing all descendants of
+ * the given
+ * category.
*/
- protected List<ParseTree> getDescendantsWithCat(ParseTree node,
+ protected List<ParseTree> getDescendantsWithCat (ParseTree node,
String nodeCat) {
ArrayList<ParseTree> descendants = new ArrayList<ParseTree>();
for (ParseTree child : getChildren(node)) {
@@ -140,38 +166,51 @@
return descendants;
}
+
/**
* Returns the first child of a node which is of a given category.
- * @param node The node.
- * @param nodeCat The node category constraining the returned child.
- * @return The first child with the given category, <tt>null</tt> if no
- * such child exists.
+ *
+ * @param node
+ * The node.
+ * @param nodeCat
+ * The node category constraining the returned child.
+ * @return The first child with the given category, <tt>null</tt>
+ * if no
+ * such child exists.
*/
- protected ParseTree getFirstChildWithCat(ParseTree node, String nodeCat) {
+ protected ParseTree getFirstChildWithCat (ParseTree node, String nodeCat) {
return getNthChildWithCat(node, nodeCat, 1);
}
-
+
+
/**
* Returns the nth child of a node which is of a given category.
- * @param node The node.
- * @param nodeCat The node category constraining the returned child.
- * @param n The index of the child to return, among all children with the
- * given category.
- * @return The nth child with the given category, <tt>null</tt> if no
- * such child exists (i.e., if n is larger than the number of children
- * with the given category).
+ *
+ * @param node
+ * The node.
+ * @param nodeCat
+ * The node category constraining the returned child.
+ * @param n
+ * The index of the child to return, among all children
+ * with the
+ * given category.
+ * @return The nth child with the given category, <tt>null</tt> if
+ * no
+ * such child exists (i.e., if n is larger than the number
+ * of children
+ * with the given category).
*/
- protected ParseTree getNthChildWithCat(ParseTree node, String nodeCat,
+ protected ParseTree getNthChildWithCat (ParseTree node, String nodeCat,
int n) {
- int counter = 0;
- for (int i = 0; i < node.getChildCount(); i++) {
- if (getNodeCat(node.getChild(i)).equals(nodeCat)) {
- counter++;
- if (counter == n) {
- return node.getChild(i);
- }
- }
- }
+ int counter = 0;
+ for (int i = 0; i < node.getChildCount(); i++) {
+ if (getNodeCat(node.getChild(i)).equals(nodeCat)) {
+ counter++;
+ if (counter == n) {
+ return node.getChild(i);
+ }
+ }
+ }
return null;
}
}
\ No newline at end of file
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
index d85c03e..7003425 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessor.java
@@ -17,9 +17,12 @@
import java.util.regex.Pattern;
/**
- * This class processes queries that define virtual collections and create
- * an KoralQuery representation of these in the <tt>collection</tt> attribute
- * of the KoralQuery tree. See the official documentation for VC query syntax
+ * This class processes queries that define virtual collections and
+ * create
+ * an KoralQuery representation of these in the <tt>collection</tt>
+ * attribute
+ * of the KoralQuery tree. See the official documentation for VC query
+ * syntax
* and functionality.
*
* @author Michael Hanl (hanl@ids-mannheim.de)
@@ -29,44 +32,51 @@
*/
public class CollectionQueryProcessor extends Antlr4AbstractQueryProcessor {
- private static Logger log =
- LoggerFactory.getLogger(CollectionQueryProcessor.class);
+ private static Logger log = LoggerFactory
+ .getLogger(CollectionQueryProcessor.class);
- public CollectionQueryProcessor() {
- KoralObjectGenerator.setQueryProcessor(this);
- }
-
- public CollectionQueryProcessor(boolean verbose) {
- KoralObjectGenerator.setQueryProcessor(this);
- CollectionQueryProcessor.verbose = verbose;
- }
-
- public CollectionQueryProcessor(String query) {
- KoralObjectGenerator.setQueryProcessor(this);
- process(query);
- }
- @Override
- public void process(String query) {
+ public CollectionQueryProcessor () {
+ KoralObjectGenerator.setQueryProcessor(this);
+ }
+
+
+ public CollectionQueryProcessor (boolean verbose) {
+ KoralObjectGenerator.setQueryProcessor(this);
+ CollectionQueryProcessor.verbose = verbose;
+ }
+
+
+ public CollectionQueryProcessor (String query) {
+ KoralObjectGenerator.setQueryProcessor(this);
+ process(query);
+ }
+
+
+ @Override
+ public void process (String query) {
ParseTree tree = parseCollectionQuery(query);
if (this.parser != null) {
super.parser = this.parser;
- } else {
- throw new NullPointerException(
- "Parser has not been instantiated!");
}
- log.info("Processing virtual collection query: "+query);
- if (verbose) System.out.println(tree.toStringTree(parser));
+ else {
+ throw new NullPointerException("Parser has not been instantiated!");
+ }
+ log.info("Processing virtual collection query: " + query);
+ if (verbose)
+ System.out.println(tree.toStringTree(parser));
if (tree != null) {
- log.debug("ANTLR parse tree: "+tree.toStringTree(parser));
- processNode(tree);
- } else {
- addError(StatusCodes.MALFORMED_QUERY,
- "Could not parse query >>> "+query+" <<<.");
- }
+ log.debug("ANTLR parse tree: " + tree.toStringTree(parser));
+ processNode(tree);
+ }
+ else {
+ addError(StatusCodes.MALFORMED_QUERY, "Could not parse query >>> "
+ + query + " <<<.");
+ }
}
- private void processNode(ParseTree node) {
+
+ private void processNode (ParseTree node) {
// Top-down processing
String nodeCat = getNodeCat(node);
openNodeCats.push(nodeCat);
@@ -77,19 +87,19 @@
System.out.println(openNodeCats);
}
- /*
+ /*
****************************************************************
- ****************************************************************
- * Processing individual node categories *
- ****************************************************************
- ****************************************************************
- */
+ ****************************************************************
+ * Processing individual node categories *
+ ****************************************************************
+ ****************************************************************
+ */
if (nodeCat.equals("relation")) {
- String operator = getNodeCat(node.getChild(1).getChild(0))
- .equals("&") ? "and" : "or";
- LinkedHashMap<String, Object> relationGroup =
- KoralObjectGenerator.makeDocGroup(operator);
+ String operator = getNodeCat(node.getChild(1).getChild(0)).equals(
+ "&") ? "and" : "or";
+ LinkedHashMap<String, Object> relationGroup = KoralObjectGenerator
+ .makeDocGroup(operator);
putIntoSuperObject(relationGroup);
objectStack.push(relationGroup);
stackedObjects++;
@@ -100,116 +110,116 @@
String field = fieldNode.getChild(0).toStringTree(parser);
ParseTree operatorNode = getFirstChildWithCat(node, "operator");
ParseTree valueNode = getFirstChildWithCat(node, "value");
- LinkedHashMap<String, Object> term =
- KoralObjectGenerator.makeDoc();
+ LinkedHashMap<String, Object> term = KoralObjectGenerator.makeDoc();
term.put("key", field);
term.putAll(parseValue(valueNode));
String match = operatorNode.getText();
term.put("match", "match:" + interpretMatchOperator(match));
if (checkOperatorValueConformance(term) == false) {
- requestMap = new LinkedHashMap<String,Object>();
- return;
+ requestMap = new LinkedHashMap<String, Object>();
+ return;
}
if (checkDateValidity(valueNode)) {
- addWarning("The collection query contains a value that looks"
- + " like a date ('"+valueNode.getText()+"') and an"
- + " operator that is only defined for strings"
- + " ('"+match+"'). The value is interpreted as"
- + " a string. Use a date operator to ensure the value"
- + " is treated as a date");
+ addWarning("The collection query contains a value that looks"
+ + " like a date ('" + valueNode.getText() + "') and an"
+ + " operator that is only defined for strings" + " ('"
+ + match + "'). The value is interpreted as"
+ + " a string. Use a date operator to ensure the value"
+ + " is treated as a date");
}
putIntoSuperObject(term);
}
-
+
if (nodeCat.equals("dateconstraint")) {
ParseTree fieldNode = getFirstChildWithCat(node, "field");
String field = fieldNode.getChild(0).toStringTree(parser);
ParseTree dateOpNode = getFirstChildWithCat(node, "dateOp");
ParseTree dateNode = getFirstChildWithCat(node, "date");
- LinkedHashMap<String, Object> term =
- KoralObjectGenerator.makeDoc();
+ LinkedHashMap<String, Object> term = KoralObjectGenerator.makeDoc();
term.put("key", field);
term.putAll(parseValue(dateNode));
String match = dateOpNode.getText();
term.put("match", "match:" + interpretMatchOperator(match));
if (checkOperatorValueConformance(term) == false) {
- requestMap = new LinkedHashMap<String,Object>();
- return;
+ requestMap = new LinkedHashMap<String, Object>();
+ return;
}
putIntoSuperObject(term);
}
-
+
if (nodeCat.equals("token")) {
- LinkedHashMap<String,Object> token =
- KoralObjectGenerator.makeToken();
- // handle negation
- List<ParseTree> negations = getChildrenWithCat(node, "!");
- boolean negated = false;
- boolean isRegex = false;
- if (negations.size() % 2 == 1) negated = true;
- if (getNodeCat(node.getChild(0)).equals("key")) {
- // no 'term' child, but direct key specification: process here
- LinkedHashMap<String,Object> term =
- KoralObjectGenerator.makeTerm();
- String key = node.getChild(0).getText();
- if (getNodeCat(node.getChild(0).getChild(0)).equals("regex")) {
- isRegex = true;
- term.put("type", "type:regex");
- key = key.substring(1,key.length()-1);
- }
- term.put("layer", "orth");
- term.put("key", key);
- String matches = negated ? "ne" : "eq";
- term.put("match", "match:"+matches);
- ParseTree flagNode = getFirstChildWithCat(node, "flag");
- if (flagNode != null) {
- // substring removes leading slash '/'
- String flag = getNodeCat(flagNode.getChild(0)).substring(1);
- if (flag.contains("i"))
- term.put("caseInsensitive", true);
- else if (flag.contains("I"))
- term.put("caseInsensitive", false);
- if (flag.contains("x")) {
- term.put("type", "type:regex");
- if (!isRegex) {
- key = QueryUtils.escapeRegexSpecialChars(key);
- }
- term.put("key", ".*?"+key+".*?"); // overwrite key
- }
- }
- token.put("wrap", term);
- } else {
- // child is 'term' or 'termGroup' -> process in extra method
- LinkedHashMap<String,Object> termOrTermGroup =
- parseTermOrTermGroup(node.getChild(1), negated);
- token.put("wrap", termOrTermGroup);
- }
- putIntoSuperObject(token);
- visited.add(node.getChild(0));
- visited.add(node.getChild(2));
- }
+ LinkedHashMap<String, Object> token = KoralObjectGenerator
+ .makeToken();
+ // handle negation
+ List<ParseTree> negations = getChildrenWithCat(node, "!");
+ boolean negated = false;
+ boolean isRegex = false;
+ if (negations.size() % 2 == 1)
+ negated = true;
+ if (getNodeCat(node.getChild(0)).equals("key")) {
+ // no 'term' child, but direct key specification: process here
+ LinkedHashMap<String, Object> term = KoralObjectGenerator
+ .makeTerm();
+ String key = node.getChild(0).getText();
+ if (getNodeCat(node.getChild(0).getChild(0)).equals("regex")) {
+ isRegex = true;
+ term.put("type", "type:regex");
+ key = key.substring(1, key.length() - 1);
+ }
+ term.put("layer", "orth");
+ term.put("key", key);
+ String matches = negated ? "ne" : "eq";
+ term.put("match", "match:" + matches);
+ ParseTree flagNode = getFirstChildWithCat(node, "flag");
+ if (flagNode != null) {
+ // substring removes leading slash '/'
+ String flag = getNodeCat(flagNode.getChild(0)).substring(1);
+ if (flag.contains("i"))
+ term.put("caseInsensitive", true);
+ else if (flag.contains("I"))
+ term.put("caseInsensitive", false);
+ if (flag.contains("x")) {
+ term.put("type", "type:regex");
+ if (!isRegex) {
+ key = QueryUtils.escapeRegexSpecialChars(key);
+ }
+ term.put("key", ".*?" + key + ".*?"); // overwrite key
+ }
+ }
+ token.put("wrap", term);
+ }
+ else {
+ // child is 'term' or 'termGroup' -> process in extra method
+ LinkedHashMap<String, Object> termOrTermGroup = parseTermOrTermGroup(
+ node.getChild(1), negated);
+ token.put("wrap", termOrTermGroup);
+ }
+ putIntoSuperObject(token);
+ visited.add(node.getChild(0));
+ visited.add(node.getChild(2));
+ }
objectsToPop.push(stackedObjects);
- /*
+ /*
****************************************************************
- ****************************************************************
- * recursion until 'request' node (root of tree) is processed *
- ****************************************************************
- ****************************************************************
- */
+ ****************************************************************
+ * recursion until 'request' node (root of tree) is processed *
+ ****************************************************************
+ ****************************************************************
+ */
for (int i = 0; i < node.getChildCount(); i++) {
ParseTree child = node.getChild(i);
processNode(child);
}
- /*
+ /*
**************************************************************
- * Stuff that happens after processing the children of a node *
- **************************************************************
- */
+ * Stuff that happens after processing the children of a node *
+ **************************************************************
+ */
if (!objectsToPop.isEmpty()) {
- int toPop = objectsToPop.pop();
+ int toPop = objectsToPop.pop();
for (int i = 0; i < toPop; i++) {
objectStack.pop();
}
@@ -219,76 +229,83 @@
}
- /**
- * Checks whether the combination of operator and value is legal
- * (inequation operators <,>,<=,>= may only be used with dates).
- */
- private boolean checkOperatorValueConformance(
+
+ /**
+ * Checks whether the combination of operator and value is legal
+ * (inequation operators <,>,<=,>= may only be used with dates).
+ */
+ private boolean checkOperatorValueConformance (
LinkedHashMap<String, Object> term) {
- String match = (String) term.get("match");
- String type = (String) term.get("type");
- if (type == null || type.equals("type:regex")) {
- if (!(match.equals("match:eq")
- || match.equals("match:ne")
- || match.equals("match:contains")
- || match.equals("match:containsnot"))) {
- addError(StatusCodes.INCOMPATIBLE_OPERATOR_AND_OPERAND,
- "You used an inequation operator with a string value.");
- return false;
- }
- }
- return true;
- }
+ String match = (String) term.get("match");
+ String type = (String) term.get("type");
+ if (type == null || type.equals("type:regex")) {
+ if (!(match.equals("match:eq") || match.equals("match:ne")
+ || match.equals("match:contains") || match
+ .equals("match:containsnot"))) {
+ addError(StatusCodes.INCOMPATIBLE_OPERATOR_AND_OPERAND,
+ "You used an inequation operator with a string value.");
+ return false;
+ }
+ }
+ return true;
+ }
- private LinkedHashMap<String, Object> parseValue(ParseTree valueNode) {
- LinkedHashMap<String, Object> map =
- new LinkedHashMap<String, Object>();
- if (getNodeCat(valueNode).equals("date")) {
- map.put("type", "type:date");
- checkDateValidity(valueNode);
- }
- if (getNodeCat(valueNode.getChild(0)).equals("regex")) {
- String regex =
- valueNode.getChild(0).getChild(0).toStringTree(parser);
- map.put("value", regex.substring(1, regex.length()-1));
- map.put("type", "type:regex");
- } else if (getNodeCat(valueNode.getChild(0)).equals("multiword")) {
- String mw = ""; // multiword
- for (int i=1; i<valueNode.getChild(0).getChildCount()-1; i++) {
- mw += valueNode.getChild(0).getChild(i).getText() + " ";
- }
- map.put("value", mw.substring(0, mw.length()-1));
- } else {
- map.put("value", valueNode.getChild(0).toStringTree(parser));
- }
- return map;
- }
- /**
- * Checks if a date
- * @param valueNode
- * @return
- */
- private boolean checkDateValidity(ParseTree valueNode) {
- Pattern p = Pattern.compile("[0-9]{4}(-([0-9]{2})(-([0-9]{2}))?)?");
- Matcher m = p.matcher(valueNode.getText());
-
- if (!m.find()) return false;
- String month = m.group(2);
- String day = m.group(4);
- if (month != null) {
- if (Integer.parseInt(month) > 12) {
- return false;
- } else if (day != null) {
- if (Integer.parseInt(day) > 31) {
- return false;
- }
- }
- }
- return true;
- }
+ private LinkedHashMap<String, Object> parseValue (ParseTree valueNode) {
+ LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
+ if (getNodeCat(valueNode).equals("date")) {
+ map.put("type", "type:date");
+ checkDateValidity(valueNode);
+ }
+ if (getNodeCat(valueNode.getChild(0)).equals("regex")) {
+ String regex = valueNode.getChild(0).getChild(0)
+ .toStringTree(parser);
+ map.put("value", regex.substring(1, regex.length() - 1));
+ map.put("type", "type:regex");
+ }
+ else if (getNodeCat(valueNode.getChild(0)).equals("multiword")) {
+ String mw = ""; // multiword
+ for (int i = 1; i < valueNode.getChild(0).getChildCount() - 1; i++) {
+ mw += valueNode.getChild(0).getChild(i).getText() + " ";
+ }
+ map.put("value", mw.substring(0, mw.length() - 1));
+ }
+ else {
+ map.put("value", valueNode.getChild(0).toStringTree(parser));
+ }
+ return map;
+ }
- private String interpretMatchOperator(String match) {
+
+ /**
+ * Checks if a date
+ *
+ * @param valueNode
+ * @return
+ */
+ private boolean checkDateValidity (ParseTree valueNode) {
+ Pattern p = Pattern.compile("[0-9]{4}(-([0-9]{2})(-([0-9]{2}))?)?");
+ Matcher m = p.matcher(valueNode.getText());
+
+ if (!m.find())
+ return false;
+ String month = m.group(2);
+ String day = m.group(4);
+ if (month != null) {
+ if (Integer.parseInt(month) > 12) {
+ return false;
+ }
+ else if (day != null) {
+ if (Integer.parseInt(day) > 31) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
+
+ private String interpretMatchOperator (String match) {
String out = null;
switch (match) {
case "<":
@@ -311,10 +328,10 @@
break;
case "~":
out = "contains";
- break;
+ break;
case "!~":
out = "containsnot";
- break;
+ break;
case "in":
out = "eq";
break;
@@ -323,21 +340,22 @@
break;
case "until":
out = "leq";
- break;
+ break;
case "since":
out = "geq";
break;
default:
- out = match;
- addError(StatusCodes.UNKNOWN_QUERY_ELEMENT,
- "Unknown operator '"+match+"'.");
- break;
+ out = match;
+ addError(StatusCodes.UNKNOWN_QUERY_ELEMENT,
+ "Unknown operator '" + match + "'.");
+ break;
}
return out;
}
-
- @Deprecated
- private String invertInequation(String op) {
+
+
+ @Deprecated
+ private String invertInequation (String op) {
String inv = null;
switch (op) {
case "lt":
@@ -356,132 +374,157 @@
return inv;
}
- private void putIntoSuperObject(LinkedHashMap<String, Object> object) {
+
+ private void putIntoSuperObject (LinkedHashMap<String, Object> object) {
putIntoSuperObject(object, 0);
}
- @SuppressWarnings({"unchecked"})
- private void putIntoSuperObject(LinkedHashMap<String, Object> object,
+
+ @SuppressWarnings({ "unchecked" })
+ private void putIntoSuperObject (LinkedHashMap<String, Object> object,
int objStackPosition) {
if (objectStack.size() > objStackPosition) {
- ArrayList<Object> topObjectOperands = (ArrayList<Object>)
- objectStack.get(objStackPosition).get("operands");
+ ArrayList<Object> topObjectOperands = (ArrayList<Object>) objectStack
+ .get(objStackPosition).get("operands");
topObjectOperands.add(object);
- } else {
-// requestMap = object;
- requestMap.put("collection", object);
+ }
+ else {
+ // requestMap = object;
+ requestMap.put("collection", object);
}
}
- private LinkedHashMap<String, Object> parseTermOrTermGroup(
- ParseTree node, boolean negated) {
- return parseTermOrTermGroup(node, negated, "token");
- }
-
+
+ private LinkedHashMap<String, Object> parseTermOrTermGroup (ParseTree node,
+ boolean negated) {
+ return parseTermOrTermGroup(node, negated, "token");
+ }
+
+
/**
- * Parses a (term) or (termGroup) node
- * @param node
- * @param negatedGlobal Indicates whether the term/termGroup is globally
- * negated, e.g. through a negation operator preceding the related token
- * like "![base=foo]". Global negation affects the "match" parameter.
- * @return A term or termGroup object, depending on input
- */
- @SuppressWarnings("unchecked")
- private LinkedHashMap<String, Object> parseTermOrTermGroup(
- ParseTree node, boolean negatedGlobal, String mode) {
- if (getNodeCat(node).equals("term")) {
- String key = null;
- LinkedHashMap<String,Object> term =
- KoralObjectGenerator.makeTerm();
- // handle negation
- boolean negated = negatedGlobal;
- boolean isRegex = false;
- List<ParseTree> negations = getChildrenWithCat(node, "!");
- if (negations.size() % 2 == 1) negated = !negated;
- // retrieve possible nodes
- ParseTree keyNode = getFirstChildWithCat(node, "key");
- ParseTree valueNode = getFirstChildWithCat(node, "value");
- ParseTree layerNode = getFirstChildWithCat(node, "layer");
- ParseTree foundryNode = getFirstChildWithCat(node, "foundry");
- ParseTree termOpNode = getFirstChildWithCat(node, "termOp");
- ParseTree flagNode = getFirstChildWithCat(node, "flag");
- // process foundry
- if (foundryNode != null)
- term.put("foundry", foundryNode.getText());
- // process layer: map "base" -> "lemma"
- if (layerNode != null) {
- String layer = layerNode.getText();
- if (layer.equals("base")) layer="lemma";
- if (mode.equals("span")) term.put("key", layer);
- else term.put("layer", layer);
- }
- // process key: 'normal' or regex?
- key = keyNode.getText();
- if (getNodeCat(keyNode.getChild(0)).equals("regex")) {
- isRegex = true;
- term.put("type", "type:regex");
- // remove leading and trailing slashes
- key = key.substring(1, key.length()-1);
- }
- if (mode.equals("span")) term.put("value", key);
- else term.put("key", key);
- // process value
- if (valueNode != null) term.put("value", valueNode.getText());
- // process operator ("match" property)
- if (termOpNode != null) {
- String termOp = termOpNode.getText();
- negated = termOp.contains("!") ? !negated : negated;
- if (!negated) term.put("match", "match:eq");
- else term.put("match", "match:ne");
- }
- // process possible flags
- if (flagNode != null) {
- // substring removes leading slash '/'
- String flag = getNodeCat(flagNode.getChild(0)).substring(1);
- if (flag.contains("i")) term.put("caseInsensitive", true);
- else if (flag.contains("I")) term.put("caseInsensitive", false);
- if (flag.contains("x")) {
- if (!isRegex) {
- key = QueryUtils.escapeRegexSpecialChars(key);
- }
- // flag 'x' allows submatches: append .*? to key
- term.put("key", ".*?"+key+".*?");
- term.put("type", "type:regex");
- }
- }
- return term;
- } else {
- // For termGroups, establish a boolean relation between operands
- // and recursively call this function with the term or termGroup
- // operands.
- LinkedHashMap<String,Object> termGroup = null;
- ParseTree leftOp = null;
- ParseTree rightOp = null;
- // check for leading/trailing parantheses
- if (!getNodeCat(node.getChild(0)).equals("("))
- leftOp = node.getChild(0);
- else leftOp = node.getChild(1);
- if (!getNodeCat(node.getChild(node.getChildCount()-1)).equals(")"))
- rightOp = node.getChild(node.getChildCount()-1);
- else rightOp = node.getChild(node.getChildCount()-2);
- // establish boolean relation
- ParseTree boolOp = getFirstChildWithCat(node, "booleanOp");
- String operator = boolOp.getText().equals("&") ? "and" : "or";
- termGroup = KoralObjectGenerator.makeTermGroup(operator);
- ArrayList<Object> operands =
- (ArrayList<Object>) termGroup.get("operands");
- // recursion with left/right operands
- operands.add(parseTermOrTermGroup(leftOp, negatedGlobal, mode));
- operands.add(parseTermOrTermGroup(rightOp, negatedGlobal, mode));
- return termGroup;
- }
- }
-
- private ParserRuleContext parseCollectionQuery(String query) {
+ * Parses a (term) or (termGroup) node
+ *
+ * @param node
+ * @param negatedGlobal
+ * Indicates whether the term/termGroup is globally
+ * negated, e.g. through a negation operator preceding
+ * the related token
+ * like "![base=foo]". Global negation affects the
+ * "match" parameter.
+ * @return A term or termGroup object, depending on input
+ */
+ @SuppressWarnings("unchecked")
+ private LinkedHashMap<String, Object> parseTermOrTermGroup (ParseTree node,
+ boolean negatedGlobal, String mode) {
+ if (getNodeCat(node).equals("term")) {
+ String key = null;
+ LinkedHashMap<String, Object> term = KoralObjectGenerator
+ .makeTerm();
+ // handle negation
+ boolean negated = negatedGlobal;
+ boolean isRegex = false;
+ List<ParseTree> negations = getChildrenWithCat(node, "!");
+ if (negations.size() % 2 == 1)
+ negated = !negated;
+ // retrieve possible nodes
+ ParseTree keyNode = getFirstChildWithCat(node, "key");
+ ParseTree valueNode = getFirstChildWithCat(node, "value");
+ ParseTree layerNode = getFirstChildWithCat(node, "layer");
+ ParseTree foundryNode = getFirstChildWithCat(node, "foundry");
+ ParseTree termOpNode = getFirstChildWithCat(node, "termOp");
+ ParseTree flagNode = getFirstChildWithCat(node, "flag");
+ // process foundry
+ if (foundryNode != null)
+ term.put("foundry", foundryNode.getText());
+ // process layer: map "base" -> "lemma"
+ if (layerNode != null) {
+ String layer = layerNode.getText();
+ if (layer.equals("base"))
+ layer = "lemma";
+ if (mode.equals("span"))
+ term.put("key", layer);
+ else
+ term.put("layer", layer);
+ }
+ // process key: 'normal' or regex?
+ key = keyNode.getText();
+ if (getNodeCat(keyNode.getChild(0)).equals("regex")) {
+ isRegex = true;
+ term.put("type", "type:regex");
+ // remove leading and trailing slashes
+ key = key.substring(1, key.length() - 1);
+ }
+ if (mode.equals("span"))
+ term.put("value", key);
+ else
+ term.put("key", key);
+ // process value
+ if (valueNode != null)
+ term.put("value", valueNode.getText());
+ // process operator ("match" property)
+ if (termOpNode != null) {
+ String termOp = termOpNode.getText();
+ negated = termOp.contains("!") ? !negated : negated;
+ if (!negated)
+ term.put("match", "match:eq");
+ else
+ term.put("match", "match:ne");
+ }
+ // process possible flags
+ if (flagNode != null) {
+ // substring removes leading slash '/'
+ String flag = getNodeCat(flagNode.getChild(0)).substring(1);
+ if (flag.contains("i"))
+ term.put("caseInsensitive", true);
+ else if (flag.contains("I"))
+ term.put("caseInsensitive", false);
+ if (flag.contains("x")) {
+ if (!isRegex) {
+ key = QueryUtils.escapeRegexSpecialChars(key);
+ }
+ // flag 'x' allows submatches: append .*? to key
+ term.put("key", ".*?" + key + ".*?");
+ term.put("type", "type:regex");
+ }
+ }
+ return term;
+ }
+ else {
+ // For termGroups, establish a boolean relation between operands
+ // and recursively call this function with the term or termGroup
+ // operands.
+ LinkedHashMap<String, Object> termGroup = null;
+ ParseTree leftOp = null;
+ ParseTree rightOp = null;
+ // check for leading/trailing parantheses
+ if (!getNodeCat(node.getChild(0)).equals("("))
+ leftOp = node.getChild(0);
+ else
+ leftOp = node.getChild(1);
+ if (!getNodeCat(node.getChild(node.getChildCount() - 1))
+ .equals(")"))
+ rightOp = node.getChild(node.getChildCount() - 1);
+ else
+ rightOp = node.getChild(node.getChildCount() - 2);
+ // establish boolean relation
+ ParseTree boolOp = getFirstChildWithCat(node, "booleanOp");
+ String operator = boolOp.getText().equals("&") ? "and" : "or";
+ termGroup = KoralObjectGenerator.makeTermGroup(operator);
+ ArrayList<Object> operands = (ArrayList<Object>) termGroup
+ .get("operands");
+ // recursion with left/right operands
+ operands.add(parseTermOrTermGroup(leftOp, negatedGlobal, mode));
+ operands.add(parseTermOrTermGroup(rightOp, negatedGlobal, mode));
+ return termGroup;
+ }
+ }
+
+
+ private ParserRuleContext parseCollectionQuery (String query) {
Lexer lexer = new CollectionQueryLexer((CharStream) null);
ParserRuleContext tree = null;
- Antlr4DescriptiveErrorListener errorListener =
- new Antlr4DescriptiveErrorListener(query);
+ Antlr4DescriptiveErrorListener errorListener = new Antlr4DescriptiveErrorListener(
+ query);
// Like p. 111
try {
@@ -499,12 +542,13 @@
parser.addErrorListener(errorListener);
// Get starting rule from parser
Method startRule = CollectionQueryParser.class.getMethod("start");
- tree = (ParserRuleContext)
- startRule.invoke(parser, (Object[]) null);
+ tree = (ParserRuleContext) startRule
+ .invoke(parser, (Object[]) null);
}
// Some things went wrong ...
catch (Exception e) {
- System.err.println("ERROR: "+errorListener.generateFullErrorMsg());
+ System.err
+ .println("ERROR: " + errorListener.generateFullErrorMsg());
System.err.println("Parsing exception message: " + e);
}
// Return the generated tree
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionTypes.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionTypes.java
index 414179b..c0398e3 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionTypes.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CollectionTypes.java
@@ -15,11 +15,13 @@
private ObjectMapper mapper;
- public CollectionTypes() {
+
+ public CollectionTypes () {
this.mapper = new ObjectMapper();
}
- public Map createGroup(String relation, String field, List terms) {
+
+ public Map createGroup (String relation, String field, List terms) {
if (relation == null)
return null;
@@ -32,7 +34,9 @@
return kgroup;
}
- public Map createTerm(String field, String subtype, String value, String type) {
+
+ public Map createTerm (String field, String subtype, String value,
+ String type) {
Map term = new LinkedHashMap<>();
if (type == null)
type = "korap:term";
@@ -45,15 +49,18 @@
return term;
}
- public Map createTerm(String field, String value, String type) {
+
+ public Map createTerm (String field, String value, String type) {
return createTerm(field, null, value, type);
}
- public Map createTerm(String field, String value) {
+
+ public Map createTerm (String field, String value) {
return createTerm(field, value, null);
}
- public Map createResourceFilter(String resource, Map value) {
+
+ public Map createResourceFilter (String resource, Map value) {
Map meta = new LinkedHashMap();
meta.put("@type", "korap:meta-filter");
meta.put("@id", "korap-filter#" + resource);
@@ -61,11 +68,14 @@
return meta;
}
- public Map createResourceFilter(String resource, String value) throws IOException {
+
+ public Map createResourceFilter (String resource, String value)
+ throws IOException {
return createResourceFilter(resource, mapify(value));
}
- public Map createResourceExtend(String resource, Map value) {
+
+ public Map createResourceExtend (String resource, Map value) {
Map meta = new LinkedHashMap();
meta.put("@type", "korap:meta-extend");
meta.put("@id", "korap-filter#" + resource);
@@ -73,14 +83,16 @@
return meta;
}
- public Map createMetaFilter(Map value) {
+
+ public Map createMetaFilter (Map value) {
Map meta = new LinkedHashMap();
meta.put("@type", "korap:meta-filter");
meta.put("@value", value);
return meta;
}
- public Map createMetaExtend(Map value) {
+
+ public Map createMetaExtend (Map value) {
Map meta = new LinkedHashMap();
meta.put("@type", "korap:meta-extend");
meta.put("@value", value);
@@ -88,7 +100,7 @@
}
- public Map mapify(String s) throws IOException {
+ public Map mapify (String s) throws IOException {
return mapper.readValue(s, Map.class);
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
index bdac037..1b22f39 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessor.java
@@ -23,7 +23,7 @@
/**
* Map representation of CosmasII syntax tree as returned by ANTLR
- *
+ *
* @author Joachim Bingel (bingel@ids-mannheim.de)
* @version 0.3
*/
@@ -32,1286 +32,1322 @@
private static Logger log = LoggerFactory
.getLogger(Cosmas2QueryProcessor.class);
- LinkedList<LinkedHashMap<String, Object>[]> toWrapStack =
- new LinkedList<LinkedHashMap<String,Object>[]>();
- /**
- * Field for repetition query (Kleene + or * operations, or
- * min/max queries: {2,4}
- */
- String repetition = "";
- /**
- * Global control structure for fieldGroups, keeps track of open
- * fieldGroups.
- */
- LinkedList<ArrayList<Object>> openFieldGroups =
- new LinkedList<ArrayList<Object>>();
- /**
- * Keeps track of how many toWrap objects there are to pop after
- * every recursion of {@link #processNode(ParseTree)}
- */
- LinkedList<Integer> toWrapsToPop = new LinkedList<Integer>();
- /**
- * Flag that indicates whether token fields or meta fields are
- * currently being processed
- */
- boolean inMeta = false;
- /**
- * If true, a sequence (OPPROX node) is governed by an OPALL node
- * (ALL()-operator), which requires to match all tokens of the
- * sequence.
- */
- boolean inOPALL = false;
- boolean inOPNHIT = false;
- /**
+ LinkedList<LinkedHashMap<String, Object>[]> toWrapStack = new LinkedList<LinkedHashMap<String, Object>[]>();
+ /**
+ * Field for repetition query (Kleene + or * operations, or
+ * min/max queries: {2,4}
+ */
+ String repetition = "";
+ /**
+ * Global control structure for fieldGroups, keeps track of open
+ * fieldGroups.
+ */
+ LinkedList<ArrayList<Object>> openFieldGroups = new LinkedList<ArrayList<Object>>();
+ /**
+ * Keeps track of how many toWrap objects there are to pop after
+ * every recursion of {@link #processNode(ParseTree)}
+ */
+ LinkedList<Integer> toWrapsToPop = new LinkedList<Integer>();
+ /**
+ * Flag that indicates whether token fields or meta fields are
+ * currently being processed
+ */
+ boolean inMeta = false;
+ /**
+ * If true, a sequence (OPPROX node) is governed by an OPALL node
+ * (ALL()-operator), which requires to match all tokens of the
+ * sequence.
+ */
+ boolean inOPALL = false;
+ boolean inOPNHIT = false;
+ /**
*
*/
- int classCounter = 1;
- boolean negate = false;
+ int classCounter = 1;
+ boolean negate = false;
- /**
- * Allows for the definition of objects to be wrapped around the
- * arguments of an operation. Each record in the table holds the
- * parent node of the argument, the number of the argument and an
- * object in whose operands list the argument shall be wrapped.
- */
- Table<Tree, Integer, LinkedHashMap<String, Object>> operandWrap =
- HashBasedTable.create();
+ /**
+ * Allows for the definition of objects to be wrapped around the
+ * arguments of an operation. Each record in the table holds the
+ * parent node of the argument, the number of the argument and an
+ * object in whose operands list the argument shall be wrapped.
+ */
+ Table<Tree, Integer, LinkedHashMap<String, Object>> operandWrap = HashBasedTable
+ .create();
- /**
- * Keeps track of all visited nodes in a tree
- */
- List<Tree> visited = new ArrayList<Tree>();
+ /**
+ * Keeps track of all visited nodes in a tree
+ */
+ List<Tree> visited = new ArrayList<Tree>();
- Integer stackedToWrap = 0;
- /**
- * A list of node categories that can be sequenced (i.e. which can
- * be in a sequence with any number of other nodes in this list)
- */
- private final List<String> sequentiableNodeTypes = Arrays
- .asList(new String[] { "OPWF", "OPLEM", "OPMORPH", "OPBEG",
- "OPEND", "OPIN", "OPBED", "OPELEM", "OPOR", "OPAND" });
- /**
- * Keeps track of sequenced nodes, i.e. nodes that implicitly
- * govern a sequence, as in (C2PQ (OPWF der) (OPWF Mann)). This is
- * necessary in order to know when to take the sequence off the
- * object stack, as the sequence is introduced by the first child
- * but cannot be closed after this first child in order not to
- * lose its siblings
- */
- private LinkedList<Tree> sequencedNodes = new LinkedList<Tree>();
+ Integer stackedToWrap = 0;
+ /**
+ * A list of node categories that can be sequenced (i.e. which can
+ * be in a sequence with any number of other nodes in this list)
+ */
+ private final List<String> sequentiableNodeTypes = Arrays
+ .asList(new String[] { "OPWF", "OPLEM", "OPMORPH", "OPBEG",
+ "OPEND", "OPIN", "OPBED", "OPELEM", "OPOR", "OPAND" });
+ /**
+ * Keeps track of sequenced nodes, i.e. nodes that implicitly
+ * govern a sequence, as in (C2PQ (OPWF der) (OPWF Mann)). This is
+ * necessary in order to know when to take the sequence off the
+ * object stack, as the sequence is introduced by the first child
+ * but cannot be closed after this first child in order not to
+ * lose its siblings
+ */
+ private LinkedList<Tree> sequencedNodes = new LinkedList<Tree>();
- private boolean nodeHasSequentiableSiblings;
+ private boolean nodeHasSequentiableSiblings;
- /**
- * Keeps track of operands lists that are to be serialised in an
- * inverted order (e.g. the IN() operator) compared to their AST
- * representation.
- */
- private LinkedList<ArrayList<Object>> invertedOperandsLists =
- new LinkedList<ArrayList<Object>>();
+ /**
+ * Keeps track of operands lists that are to be serialised in an
+ * inverted order (e.g. the IN() operator) compared to their AST
+ * representation.
+ */
+ private LinkedList<ArrayList<Object>> invertedOperandsLists = new LinkedList<ArrayList<Object>>();
- /**
- * @param tree
- * The syntax tree as returned by ANTLR
- * @param parser
- * The ANTLR parser instance that generated the parse
- * tree
- * @throws QueryException
- */
- public Cosmas2QueryProcessor (String query) {
- KoralObjectGenerator.setQueryProcessor(this);
- this.query = query;
- process(query);
- log.info(">>> " + requestMap.get("query") + " <<<");
- }
- @Override
- public void process(String query) {
- Tree tree = null;
- tree = parseCosmasQuery(query);
- log.info("Processing CosmasII query: " + query);
- if (tree != null) {
- log.debug("ANTLR parse tree: " + tree.toStringTree());
- processNode(tree);
- }
- }
+ /**
+ * @param tree
+ * The syntax tree as returned by ANTLR
+ * @param parser
+ * The ANTLR parser instance that generated the parse
+ * tree
+ * @throws QueryException
+ */
+ public Cosmas2QueryProcessor (String query) {
+ KoralObjectGenerator.setQueryProcessor(this);
+ this.query = query;
+ process(query);
+ log.info(">>> " + requestMap.get("query") + " <<<");
+ }
- private void processNode(Tree node) {
- // Top-down processing
- if (visited.contains(node))
- return;
- else
- visited.add(node);
- String nodeCat = getNodeCat(node);
- openNodeCats.push(nodeCat);
+ @Override
+ public void process (String query) {
+ Tree tree = null;
+ tree = parseCosmasQuery(query);
+ log.info("Processing CosmasII query: " + query);
+ if (tree != null) {
+ log.debug("ANTLR parse tree: " + tree.toStringTree());
+ processNode(tree);
+ }
+ }
- stackedObjects = 0;
- stackedToWrap = 0;
- if (verbose) {
- System.err.println(" " + objectStack);
- System.out.println(openNodeCats);
- }
+ private void processNode (Tree node) {
+ // Top-down processing
+ if (visited.contains(node))
+ return;
+ else
+ visited.add(node);
- /* ***************************************
- * Processing individual node categories *
- * ***************************************
- */
+ String nodeCat = getNodeCat(node);
+ openNodeCats.push(nodeCat);
- // Check for potential implicit sequences as in (C2PQ (OPWF
- // der) (OPWF Mann)). The sequence is introduced
- // by the first child if it (and its siblings) is
- // sequentiable.
- if (sequentiableNodeTypes.contains(nodeCat)) {
- // for each node, check if parent has more than one child
- // (-> could be implicit sequence)
- Tree parent = node.getParent();
- if (parent.getChildCount() > 1) {
- // if node is first child of parent...
- if (node == parent.getChild(0)) {
- nodeHasSequentiableSiblings = false;
- for (int i = 1; i < parent.getChildCount(); i++) {
- if (sequentiableNodeTypes.contains(getNodeCat(parent
- .getChild(i)))) {
- nodeHasSequentiableSiblings = true;
- continue;
- }
- }
- if (nodeHasSequentiableSiblings) {
- // Step I: create sequence
- LinkedHashMap<String, Object> sequence =
- KoralObjectGenerator.makeGroup("sequence");
- // push sequence on object stack but don't
- // increment stackedObjects counter since
- // we've got to wait until the parent node is
- // processed - therefore, add the parent
- // to the sequencedNodes list and remove the
- // sequence from the stack when the parent
- // has been processed
- objectStack.push(sequence);
- sequencedNodes.push(parent);
- // Step II: decide where to put sequence
- putIntoSuperObject(sequence, 1);
- }
+ stackedObjects = 0;
+ stackedToWrap = 0;
+
+ if (verbose) {
+ System.err.println(" " + objectStack);
+ System.out.println(openNodeCats);
+ }
+
+ /* ***************************************
+ * Processing individual node categories *
+ * ***************************************
+ */
+
+ // Check for potential implicit sequences as in (C2PQ (OPWF
+ // der) (OPWF Mann)). The sequence is introduced
+ // by the first child if it (and its siblings) is
+ // sequentiable.
+ if (sequentiableNodeTypes.contains(nodeCat)) {
+ // for each node, check if parent has more than one child
+ // (-> could be implicit sequence)
+ Tree parent = node.getParent();
+ if (parent.getChildCount() > 1) {
+ // if node is first child of parent...
+ if (node == parent.getChild(0)) {
+ nodeHasSequentiableSiblings = false;
+ for (int i = 1; i < parent.getChildCount(); i++) {
+ if (sequentiableNodeTypes.contains(getNodeCat(parent
+ .getChild(i)))) {
+ nodeHasSequentiableSiblings = true;
+ continue;
}
}
- }
-
- if (nodeCat.equals("OPWF") || nodeCat.equals("OPLEM")) {
- processOPWF_OPLEM(node);
- }
-
- if (nodeCat.equals("OPMORPH")) {
- processOPMORPH(node);
- }
-
- if (nodeCat.equals("OPELEM")) {
- processOPELEM(node);
- }
-
- if (nodeCat.equals("OPLABEL")) {
- processOPLABEL(node);
- }
-
- if (nodeCat.equals("OPAND") || nodeCat.equals("OPNOT")) {
- processOPAND_OPNOT(node);
- }
-
- if (nodeCat.equals("OPOR")) {
- processOPOR(node);
- }
-
- if (nodeCat.equals("OPPROX")) {
- processOPPROX(node);
- }
-
- // inlcusion or overlap
- if (nodeCat.equals("OPIN") || nodeCat.equals("OPOV")) {
- processOPIN_OPOV(node);
- }
-
- // Wrap the argument of an #IN operator in a previously
- // defined container
- if (nodeCat.equals("ARG1") || nodeCat.equals("ARG2")) {
- processARG1_ARG2(node);
- }
-
- if (nodeCat.equals("OPALL")) {
- inOPALL = true;
- }
-
- if (nodeCat.equals("OPNHIT")) {
- processOPNHIT(node);
- }
-
- if (nodeCat.equals("OPEND") || nodeCat.equals("OPBEG")) {
- processOPEND_OPBEG(node);
- }
-
- if (nodeCat.equals("OPBED")) {
- processOPBED(node);
- }
- objectsToPop.push(stackedObjects);
- toWrapsToPop.push(stackedToWrap);
-
- /*
- * ***************************************************************
- * ***************************************************************
- * recursion until 'request' node (root of tree) is processed
- * *
- * ***********************************************************
- * ****
- * ********************************************************
- * *******
- */
- for (int i = 0; i < node.getChildCount(); i++) {
- Tree child = node.getChild(i);
- processNode(child);
- }
-
- /*
- * *************************************************************
- * Stuff that happens after processing the children of a node
- * *
- * ***********************************************************
- * **
- */
-
- // remove sequence from object stack if node is implicitly
- // sequenced
- if (sequencedNodes.size() > 0) {
- if (node == sequencedNodes.getFirst()) {
- objectStack.pop();
- sequencedNodes.pop();
+ if (nodeHasSequentiableSiblings) {
+ // Step I: create sequence
+ LinkedHashMap<String, Object> sequence = KoralObjectGenerator
+ .makeGroup("sequence");
+ // push sequence on object stack but don't
+ // increment stackedObjects counter since
+ // we've got to wait until the parent node is
+ // processed - therefore, add the parent
+ // to the sequencedNodes list and remove the
+ // sequence from the stack when the parent
+ // has been processed
+ objectStack.push(sequence);
+ sequencedNodes.push(parent);
+ // Step II: decide where to put sequence
+ putIntoSuperObject(sequence, 1);
}
}
-
- for (int i = 0; i < objectsToPop.get(0); i++) {
- objectStack.pop();
- }
- objectsToPop.pop();
-
- // if (!toWrapStack.isEmpty())
- // System.err.println(toWrapStack.get(0)[0]);
- for (int i = 0; i < toWrapsToPop.get(0); i++) {
- putIntoSuperObject(wrap(toWrapStack.pop()));
- }
- toWrapsToPop.pop();
-
- if (nodeCat.equals("ARG2") && openNodeCats.get(1).equals("OPNOT")) {
- negate = false;
- }
-
- if (nodeCat.equals("OPALL")) {
- inOPALL = false;
- }
-
- openNodeCats.pop();
}
+ }
- private void processOPEND_OPBEG(Tree node) {
- // Step I: create group
- String nodeCat = getNodeCat(node);
- LinkedHashMap<String, Object> beggroup = new LinkedHashMap<String, Object>();
- beggroup.put("@type", "koral:reference");
- beggroup.put("operation", "operation:focus");
- ArrayList<Integer> spanRef = new ArrayList<Integer>();
- if (nodeCat.equals("OPBEG")) {
- spanRef.add(0);
- spanRef.add(1);
+ if (nodeCat.equals("OPWF") || nodeCat.equals("OPLEM")) {
+ processOPWF_OPLEM(node);
+ }
+
+ if (nodeCat.equals("OPMORPH")) {
+ processOPMORPH(node);
+ }
+
+ if (nodeCat.equals("OPELEM")) {
+ processOPELEM(node);
+ }
+
+ if (nodeCat.equals("OPLABEL")) {
+ processOPLABEL(node);
+ }
+
+ if (nodeCat.equals("OPAND") || nodeCat.equals("OPNOT")) {
+ processOPAND_OPNOT(node);
+ }
+
+ if (nodeCat.equals("OPOR")) {
+ processOPOR(node);
+ }
+
+ if (nodeCat.equals("OPPROX")) {
+ processOPPROX(node);
+ }
+
+ // inlcusion or overlap
+ if (nodeCat.equals("OPIN") || nodeCat.equals("OPOV")) {
+ processOPIN_OPOV(node);
+ }
+
+ // Wrap the argument of an #IN operator in a previously
+ // defined container
+ if (nodeCat.equals("ARG1") || nodeCat.equals("ARG2")) {
+ processARG1_ARG2(node);
+ }
+
+ if (nodeCat.equals("OPALL")) {
+ inOPALL = true;
+ }
+
+ if (nodeCat.equals("OPNHIT")) {
+ processOPNHIT(node);
+ }
+
+ if (nodeCat.equals("OPEND") || nodeCat.equals("OPBEG")) {
+ processOPEND_OPBEG(node);
+ }
+
+ if (nodeCat.equals("OPBED")) {
+ processOPBED(node);
+ }
+ objectsToPop.push(stackedObjects);
+ toWrapsToPop.push(stackedToWrap);
+
+ /*
+ * ***************************************************************
+ * ***************************************************************
+ * recursion until 'request' node (root of tree) is processed
+ * *
+ * ***********************************************************
+ * ****
+ * ********************************************************
+ * *******
+ */
+ for (int i = 0; i < node.getChildCount(); i++) {
+ Tree child = node.getChild(i);
+ processNode(child);
+ }
+
+ /*
+ * *************************************************************
+ * Stuff that happens after processing the children of a node
+ * *
+ * ***********************************************************
+ * **
+ */
+
+ // remove sequence from object stack if node is implicitly
+ // sequenced
+ if (sequencedNodes.size() > 0) {
+ if (node == sequencedNodes.getFirst()) {
+ objectStack.pop();
+ sequencedNodes.pop();
+ }
+ }
+
+ for (int i = 0; i < objectsToPop.get(0); i++) {
+ objectStack.pop();
+ }
+ objectsToPop.pop();
+
+ // if (!toWrapStack.isEmpty())
+ // System.err.println(toWrapStack.get(0)[0]);
+ for (int i = 0; i < toWrapsToPop.get(0); i++) {
+ putIntoSuperObject(wrap(toWrapStack.pop()));
+ }
+ toWrapsToPop.pop();
+
+ if (nodeCat.equals("ARG2") && openNodeCats.get(1).equals("OPNOT")) {
+ negate = false;
+ }
+
+ if (nodeCat.equals("OPALL")) {
+ inOPALL = false;
+ }
+
+ openNodeCats.pop();
+ }
+
+
+ private void processOPEND_OPBEG (Tree node) {
+ // Step I: create group
+ String nodeCat = getNodeCat(node);
+ LinkedHashMap<String, Object> beggroup = new LinkedHashMap<String, Object>();
+ beggroup.put("@type", "koral:reference");
+ beggroup.put("operation", "operation:focus");
+ ArrayList<Integer> spanRef = new ArrayList<Integer>();
+ if (nodeCat.equals("OPBEG")) {
+ spanRef.add(0);
+ spanRef.add(1);
+ }
+ else if (nodeCat.equals("OPEND")) {
+ spanRef.add(-1);
+ spanRef.add(1);
+ }
+ beggroup.put("spanRef", spanRef);
+ beggroup.put("operands", new ArrayList<Object>());
+ objectStack.push(beggroup);
+ stackedObjects++;
+
+ // Step II: decide where to put
+ putIntoSuperObject(beggroup, 1);
+ }
+
+
+ private void processOPBED (Tree node) {
+ // Node structure is (OPBED X+ (OPTS (TPBEG tpos*) (TPEND
+ // tpos*)))
+ // X is some segment, TPBEG or TPEND must be present
+ // (inclusive OR)
+ // tpos is a three-char string of the form "[+-]?[spt][ae]".
+ // s/p/t indicates span, a/e beginning/end, - means negation
+ // See C-II QL documentation for more detail:
+ // http://www.ids-mannheim.de/cosmas2/win-app/hilfe/suchanfrage/eingabe-grafisch/syntax/textpositionen.html
+
+ // Step I: create group
+ int optsChild = node.getChildCount() - 1;
+ Tree begConditions = getFirstChildWithCat(node.getChild(optsChild),
+ "TPBEG");
+ Tree endConditions = getFirstChildWithCat(node.getChild(optsChild),
+ "TPEND");
+
+ LinkedHashMap<String, Object> submatchgroup = KoralObjectGenerator
+ .makeReference(classCounter + 128);
+ ArrayList<Object> submatchOperands = new ArrayList<Object>();
+ submatchgroup.put("operands", submatchOperands);
+ putIntoSuperObject(submatchgroup);
+
+ // Step II: collect all conditions, create groups for them in
+ // processPositionCondition()
+ ArrayList<Object> distributedOperands = new ArrayList<Object>();
+ ArrayList<LinkedHashMap<String, Object>> conditionGroups = new ArrayList<LinkedHashMap<String, Object>>();
+ if (begConditions != null) {
+ for (Tree condition : getChildren(begConditions)) {
+ conditionGroups.add(processPositionCondition(condition,
+ distributedOperands, "beg"));
+ }
+ }
+ if (endConditions != null) {
+ for (Tree condition : getChildren(endConditions)) {
+ conditionGroups.add(processPositionCondition(condition,
+ distributedOperands, "end"));
+ }
+ }
+ // Step III: insert conditions. need to stack matches-groups
+ // because position groups may only have two operands
+ // indicates where to insert next condition group
+ ArrayList<Object> currentLowestOperands = submatchOperands;
+ int conditionCount = 0;
+ for (LinkedHashMap<String, Object> conditionGroup : conditionGroups) {
+ conditionCount++;
+ if (conditionGroups.size() == 1) {
+ submatchOperands.add(conditionGroup);
+ }
+ else if (conditionCount < conditionGroups.size()) {
+ LinkedHashMap<String, Object> matchesGroup = KoralObjectGenerator
+ .makePosition(new String[] { "frames:matches" });
+ @SuppressWarnings("unchecked")
+ ArrayList<Object> matchesOperands = (ArrayList<Object>) matchesGroup
+ .get("operands");
+ matchesOperands.add(conditionGroup);
+ // matches groups that are embedded at the second or
+ // lower level receive an additional
+ // focus to grep out only the query term to which the
+ // constraint applies
+ if (conditionCount > 1) {
+ LinkedHashMap<String, Object> focus = KoralObjectGenerator
+ .makeReference(classCounter + 128 - 2);
+ ArrayList<Object> focusOperands = new ArrayList<Object>();
+ focus.put("operands", focusOperands);
+ focusOperands.add(matchesGroup);
+ currentLowestOperands.add(focus);
}
- else if (nodeCat.equals("OPEND")) {
- spanRef.add(-1);
- spanRef.add(1);
+ else {
+ currentLowestOperands.add(matchesGroup);
}
- beggroup.put("spanRef", spanRef);
- beggroup.put("operands", new ArrayList<Object>());
- objectStack.push(beggroup);
+ currentLowestOperands = matchesOperands;
+ }
+ else {
+ currentLowestOperands.add(conditionGroup);
+ }
+ }
+ }
+
+
+ private void processOPNHIT (Tree node) {
+ Integer[] classRef = new Integer[] { classCounter + 128 + 1,
+ classCounter + 128 + 2 };
+ // classRef.add(classCounter + 1); // yes, do this twice (two
+ // classes)!
+ LinkedHashMap<String, Object> group = KoralObjectGenerator
+ .makeReference(classCounter + 128);
+ LinkedHashMap<String, Object> classRefCheck = KoralObjectGenerator
+ .makeClassRefOp("classRefOp:inversion", classRef,
+ classCounter + 128);
+ ArrayList<Object> operands = new ArrayList<Object>();
+ operands.add(classRefCheck);
+ group.put("operands", operands);
+ classCounter++;
+ // direct child is OPPROX
+ wrapOperandInClass(node.getChild(0), 1, 128 + classCounter++);
+ wrapOperandInClass(node.getChild(0), 2, 128 + classCounter++);
+ objectStack.push(classRefCheck);
+ stackedObjects++;
+ putIntoSuperObject(group, 1);
+ }
+
+
+ private void processARG1_ARG2 (Tree node) {
+ String nodeCat = getNodeCat(node);
+ Tree parent = node.getParent();
+ if (operandWrap.containsRow(parent)) {
+ // Step I: create group
+ int argNr = nodeCat.equals("ARG1") ? 1 : 2;
+ LinkedHashMap<String, Object> container = operandWrap.row(parent)
+ .get(argNr);
+ // Step II: ingest
+ if (container != null) {
+ objectStack.push(container);
stackedObjects++;
-
- // Step II: decide where to put
- putIntoSuperObject(beggroup, 1);
+ putIntoSuperObject(container, 1);
}
+ }
+ }
- private void processOPBED(Tree node) {
- // Node structure is (OPBED X+ (OPTS (TPBEG tpos*) (TPEND
- // tpos*)))
- // X is some segment, TPBEG or TPEND must be present
- // (inclusive OR)
- // tpos is a three-char string of the form "[+-]?[spt][ae]".
- // s/p/t indicates span, a/e beginning/end, - means negation
- // See C-II QL documentation for more detail:
- // http://www.ids-mannheim.de/cosmas2/win-app/hilfe/suchanfrage/eingabe-grafisch/syntax/textpositionen.html
- // Step I: create group
- int optsChild = node.getChildCount() - 1;
- Tree begConditions = getFirstChildWithCat(node.getChild(optsChild),
- "TPBEG");
- Tree endConditions = getFirstChildWithCat(node.getChild(optsChild),
- "TPEND");
+ @SuppressWarnings("unchecked")
+ private void processOPIN_OPOV (Tree node) {
+ // Step I: create group
+ String nodeCat = getNodeCat(node);
+ wrapOperandInClass(node, 2, 128 + classCounter++);
+ wrapOperandInClass(node, 1, 128 + classCounter++);
+ // LinkedHashMap<String, Object> posgroup =
+ // makePosition(null);
+ LinkedHashMap<String, Object> posGroup = KoralObjectGenerator
+ .makeGroup("position");
+ LinkedHashMap<String, Object> positionOptions;
+ // posgroup
+ if (nodeCat.equals("OPIN")) {
+ positionOptions = parseOPINOptions(node);
+ }
+ else {
+ positionOptions = parseOPOVOptions(node);
+ }
+ posGroup.put("frames", positionOptions.get("frames"));
+ posGroup.put("frame", positionOptions.get("frame"));
+ if (positionOptions.containsKey("exclude")) {
+ posGroup.put("exclude", positionOptions.get("exclude"));
+ }
+ objectStack.push(posGroup);
+ // mark this an inverted operands object
+ invertedOperandsLists
+ .push((ArrayList<Object>) posGroup.get("operands"));
+ stackedObjects++;
+ // Step II: wrap in classRefCheck and/or focus and decide where to put
+ ArrayList<String> check = (ArrayList<String>) positionOptions
+ .get("classRefCheck");
+ Integer[] classIn = new Integer[] { classCounter + 128 - 2,
+ classCounter + 128 - 1 };
+ LinkedHashMap<String, Object> topGroup;
+ if (!check.isEmpty()) {
+ // wrap position in a classRefCheck
+ topGroup = KoralObjectGenerator.makeClassRefCheck(check, classIn,
+ classCounter + 128);
+ ((ArrayList<Object>) topGroup.get("operands")).add(posGroup);
+ }
+ else {
+ topGroup = posGroup;
+ }
+ LinkedHashMap<String, Object> focusGroup = null;
+ if ((boolean) positionOptions.get("matchall") == true) {
+ focusGroup = KoralObjectGenerator.makeClassRefOp(
+ "classRefOp:delete",
+ new Integer[] { 128 + classCounter++ }, 128 + classCounter);
+ ((ArrayList<Object>) focusGroup.get("operands")).add(topGroup);
+ }
+ else { // match only first argument
+ focusGroup = KoralObjectGenerator.wrapInReference(topGroup,
+ classCounter + 128 - 1);
+ classCounter++;
+ }
+ // wrap in 'merge' operation if grouping option is set
+ if (positionOptions.containsKey("grouping")) {
+ if (positionOptions.get("grouping").equals(true)) {
+ LinkedHashMap<String, Object> mergeOperation = KoralObjectGenerator
+ .makeGroup("merge");
+ ArrayList<Object> mergeOperands = (ArrayList<Object>) mergeOperation
+ .get("operands");
+ mergeOperands.add(focusGroup);
+ focusGroup = mergeOperation;
+ }
+ }
+ putIntoSuperObject(focusGroup, 1);
+ }
- LinkedHashMap<String, Object> submatchgroup =
- KoralObjectGenerator.makeReference(classCounter+128);
- ArrayList<Object> submatchOperands = new ArrayList<Object>();
- submatchgroup.put("operands", submatchOperands);
- putIntoSuperObject(submatchgroup);
- // Step II: collect all conditions, create groups for them in
- // processPositionCondition()
- ArrayList<Object> distributedOperands = new ArrayList<Object>();
- ArrayList<LinkedHashMap<String, Object>> conditionGroups =
- new ArrayList<LinkedHashMap<String, Object>>();
- if (begConditions != null) {
- for (Tree condition : getChildren(begConditions)) {
- conditionGroups.add(processPositionCondition(condition,
- distributedOperands, "beg"));
- }
+ @SuppressWarnings("unchecked")
+ private void processOPPROX (Tree node) {
+ // collect info
+ Tree prox_opts = node.getChild(0);
+ Tree typ = prox_opts.getChild(0);
+ Tree dist_list = prox_opts.getChild(1);
+ // Step I: create group
+ LinkedHashMap<String, Object> group = KoralObjectGenerator
+ .makeGroup("sequence");
+
+ ArrayList<Object> constraints = new ArrayList<Object>();
+ boolean exclusion = typ.getChild(0).toStringTree().equals("EXCL");
+
+ boolean inOrder = false;
+ boolean invertedOperands = false;
+
+ group.put("inOrder", inOrder);
+ group.put("distances", constraints);
+
+ boolean putIntoOverlapDisjunction = false;
+
+ int min = 0, max = 0;
+ // possibly several distance constraints
+ for (int i = 0; i < dist_list.getChildCount(); i++) {
+ String direction = dist_list.getChild(i).getChild(0).getChild(0)
+ .toStringTree().toLowerCase();
+ String minStr = dist_list.getChild(i).getChild(1).getChild(0)
+ .toStringTree();
+ String maxStr = dist_list.getChild(i).getChild(1).getChild(1)
+ .toStringTree();
+ String meas = dist_list.getChild(i).getChild(2).getChild(0)
+ .toStringTree();
+ if (minStr.equals("VAL0")) {
+ minStr = "0";
+ }
+ min = Integer.parseInt(minStr);
+ max = Integer.parseInt(maxStr);
+ // If zero word-distance, wrap this sequence in a
+ // disjunction along with an overlap position
+ // between the two operands
+ /*
+ * XXX: This is currently deactivated. Uncomment to
+ * activate treatment of zero-word distances as
+ * overlap-alternatives (see google doc on special
+ * distances serialization)
+ *
+ * if (meas.equals("w") && min == 0) { min = 1;
+ * putIntoOverlapDisjunction = true; }
+ */
+ if (!meas.equals("w") && min == 0) {
+ processSpanDistance(meas, min, max);
+ }
+ LinkedHashMap<String, Object> distance = KoralObjectGenerator
+ .makeDistance(meas, min, max);
+ // override @type, min/max to be treated according to
+ // Cosmas particularities
+ distance.put("@type", "cosmas:distance");
+ if (exclusion) {
+ distance.put("exclude", true);
+ }
+ // if (! openNodeCats.get(1).equals("OPNHIT")) {
+ constraints.add(distance);
+ // }
+ if (i == 0) {
+ if (direction.equals("plus")) {
+ inOrder = true;
}
- if (endConditions != null) {
- for (Tree condition : getChildren(endConditions)) {
- conditionGroups.add(processPositionCondition(condition,
- distributedOperands, "end"));
- }
+ else if (direction.equals("minus")) {
+ inOrder = true;
+ invertedOperands = true;
}
- // Step III: insert conditions. need to stack matches-groups
- // because position groups may only have two operands
- // indicates where to insert next condition group
- ArrayList<Object> currentLowestOperands = submatchOperands;
- int conditionCount = 0;
- for (LinkedHashMap<String, Object> conditionGroup : conditionGroups) {
- conditionCount++;
- if (conditionGroups.size() == 1) {
- submatchOperands.add(conditionGroup);
- }
- else if (conditionCount < conditionGroups.size()) {
- LinkedHashMap<String, Object> matchesGroup = KoralObjectGenerator
- .makePosition(new String[] { "frames:matches" });
- @SuppressWarnings("unchecked")
- ArrayList<Object> matchesOperands =
- (ArrayList<Object>) matchesGroup.get("operands");
- matchesOperands.add(conditionGroup);
- // matches groups that are embedded at the second or
- // lower level receive an additional
- // focus to grep out only the query term to which the
- // constraint applies
- if (conditionCount > 1) {
- LinkedHashMap<String, Object> focus =
- KoralObjectGenerator.makeReference(classCounter +128 - 2);
- ArrayList<Object> focusOperands = new ArrayList<Object>();
- focus.put("operands", focusOperands);
- focusOperands.add(matchesGroup);
- currentLowestOperands.add(focus);
+ else if (direction.equals("both")) {
+ inOrder = false;
+ }
+ }
+ }
+ group.put("inOrder", inOrder);
+ LinkedHashMap<String, Object> embeddedSequence = group;
+
+ if (!(openNodeCats.get(1).equals("OPBEG")
+ || openNodeCats.get(1).equals("OPEND") || inOPALL || openNodeCats
+ .get(1).equals("OPNHIT"))) {
+ wrapOperandInClass(node, 1, 128 + classCounter);
+ wrapOperandInClass(node, 2, 128 + classCounter);
+ // Deactivated, uncomment to wrap sequence in reference.
+ // group = KoralObjectGenerator.wrapInReference(group,
+ // classCounter++);
+ classCounter++;
+ }
+ else if (openNodeCats.get(1).equals("OPNHIT")) {
+ LinkedHashMap<String, Object> repetition = KoralObjectGenerator
+ .makeRepetition(min, max);
+ ((ArrayList<Object>) repetition.get("operands"))
+ .add(KoralObjectGenerator.makeToken());
+ // TODO go on with this: put the repetition into a class
+ // and put it in between the operands
+ // -> what if there's several distance constraints. with
+ // different keys, like /w4,s0?
+ }
+
+ // LinkedHashMap<String, Object> sequence = null;
+ // if (putIntoOverlapDisjunction) {
+ // sequence = embeddedSequence;
+ // group = KoralObjectGenerator.makeGroup("or");
+ // ArrayList<Object> disjOperands =
+ // (ArrayList<Object>) group.get("operands");
+ // LinkedHashMap<String, Object> overlapsGroup = KoralObjectGenerator
+ // .makePosition(new String[0]);
+ //
+ // ArrayList<Object> overlapsOperands =
+ // (ArrayList<Object>) overlapsGroup.get("operands");
+ // // this ensures identity of the operands lists and thereby
+ // // a distribution of the operands for both created objects
+ // sequence.put("operands", overlapsOperands);
+ // if (invertedOperands) {
+ // invertedOperandsLists.push(overlapsOperands);
+ // }
+ // disjOperands.add(overlapsGroup);
+ // disjOperands.add(KoralObjectGenerator.wrapInReference(sequence, 0));
+ // // Step II: decide where to put
+ // putIntoSuperObject(group, 0);
+ // objectStack.push(sequence);
+ // }
+ // else {
+ if (invertedOperands) {
+ ArrayList<Object> operands = (ArrayList<Object>) embeddedSequence
+ .get("operands");
+ invertedOperandsLists.push(operands);
+ }
+ // Step II: decide where to put
+ putIntoSuperObject(group, 0);
+ objectStack.push(embeddedSequence);
+ // }
+ stackedObjects++;
+ visited.add(node.getChild(0));
+ }
+
+
+ private void processOPOR (Tree node) {
+ // Step I: create group
+ LinkedHashMap<String, Object> disjunction = KoralObjectGenerator
+ .makeGroup("disjunction");
+ objectStack.push(disjunction);
+ stackedObjects++;
+ // Step II: decide where to put
+ putIntoSuperObject(disjunction, 1);
+ }
+
+
+ private void processOPAND_OPNOT (Tree node) {
+ // Step I: create group
+ String nodeCat = getNodeCat(node);
+ LinkedHashMap<String, Object> distgroup = KoralObjectGenerator
+ .makeGroup("sequence");
+ ArrayList<Object> distances = new ArrayList<Object>();
+ LinkedHashMap<String, Object> zerodistance = KoralObjectGenerator
+ .makeDistance("t", 0, 0);
+ zerodistance.put("@type", "cosmas:distance"); // overwrite @type: cosmas:distance!
+ if (nodeCat.equals("OPNOT"))
+ zerodistance.put("exclude", true);
+ distances.add(zerodistance);
+ distgroup.put("distances", distances);
+ distgroup.put("operands", new ArrayList<Object>());
+ objectStack.push(distgroup);
+ stackedObjects++;
+ // Step II: decide where to put
+ putIntoSuperObject(distgroup, 1);
+ }
+
+
+ private void processOPLABEL (Tree node) {
+ // Step I: create element
+ String key = node.getChild(0).toStringTree().replaceAll("<|>", "");
+ LinkedHashMap<String, Object> elem = KoralObjectGenerator.makeSpan(key);
+ // Step II: decide where to put
+ putIntoSuperObject(elem);
+ }
+
+
+ @SuppressWarnings("unchecked")
+ private void processOPELEM (Tree node) {
+ // Step I: create element
+ LinkedHashMap<String, Object> span = KoralObjectGenerator.makeSpan();
+ if (node.getChild(0).toStringTree().equals("EMPTY")) {
+ addError(
+ StatusCodes.MALFORMED_QUERY,
+ "Empty #ELEM() operator."
+ + " Please specify a valid element key (like 's' for sentence).");
+ return;
+ }
+ else {
+ int elname = 0;
+ Tree elnameNode = getFirstChildWithCat(node, "ELNAME");
+ if (elnameNode != null) {
+ span.put("key", elnameNode.getChild(0).toStringTree()
+ .toLowerCase());
+ elname = 1;
+ }
+ if (node.getChildCount() > elname) {
+ /*
+ * Attributes can carry several values, like #ELEM(W
+ * ANA != 'N V'), denoting a word whose POS is neither
+ * N nor V. When seeing this, create a sub-termGroup
+ * and put it into the top-level term group, but only
+ * if there are other attributes in that group. If
+ * not, put the several values as distinct
+ * attr-val-pairs into the top-level group (in order
+ * to avoid a top-level group that only contains a
+ * sub-group).
+ */
+ LinkedHashMap<String, Object> termGroup = KoralObjectGenerator
+ .makeTermGroup("and");
+ ArrayList<Object> termGroupOperands = (ArrayList<Object>) termGroup
+ .get("operands");
+ for (int i = elname; i < node.getChildCount(); i++) {
+ Tree attrNode = node.getChild(i);
+ if (attrNode.getChildCount() == 2) {
+ LinkedHashMap<String, Object> term = KoralObjectGenerator
+ .makeTerm();
+ termGroupOperands.add(term);
+ String layer = attrNode.getChild(0).toStringTree();
+ String[] splitted = layer.split("/");
+ if (splitted.length > 1) {
+ term.put("foundry", splitted[0]);
+ layer = splitted[1];
}
- else {
- currentLowestOperands.add(matchesGroup);
- }
- currentLowestOperands = matchesOperands;
+ term.put("layer", translateMorph(layer));
+ term.put("key", attrNode.getChild(1).toStringTree());
+ String match = getNodeCat(attrNode).equals("EQ") ? "eq"
+ : "ne";
+ term.put("match", "match:" + match);
}
else {
- currentLowestOperands.add(conditionGroup);
- }
- }
- }
-
- private void processOPNHIT(Tree node) {
- Integer[] classRef = new Integer[] { classCounter + 128 + 1,
- classCounter + 128 + 2 };
- // classRef.add(classCounter + 1); // yes, do this twice (two
- // classes)!
- LinkedHashMap<String, Object> group =
- KoralObjectGenerator.makeReference(classCounter+128);
- LinkedHashMap<String, Object> classRefCheck =
- KoralObjectGenerator.makeClassRefOp("classRefOp:inversion", classRef,
- classCounter+128);
- ArrayList<Object> operands = new ArrayList<Object>();
- operands.add(classRefCheck);
- group.put("operands", operands);
- classCounter++;
- // direct child is OPPROX
- wrapOperandInClass(node.getChild(0), 1, 128+classCounter++);
- wrapOperandInClass(node.getChild(0), 2, 128+classCounter++);
- objectStack.push(classRefCheck);
- stackedObjects++;
- putIntoSuperObject(group, 1);
- }
-
- private void processARG1_ARG2(Tree node) {
- String nodeCat = getNodeCat(node);
- Tree parent = node.getParent();
- if (operandWrap.containsRow(parent)) {
- // Step I: create group
- int argNr = nodeCat.equals("ARG1") ? 1 : 2;
- LinkedHashMap<String, Object> container = operandWrap.row(parent)
- .get(argNr);
- // Step II: ingest
- if (container != null) {
- objectStack.push(container);
- stackedObjects++;
- putIntoSuperObject(container, 1);
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- private void processOPIN_OPOV(Tree node) {
- // Step I: create group
- String nodeCat = getNodeCat(node);
- wrapOperandInClass(node, 2, 128+classCounter++);
- wrapOperandInClass(node, 1, 128+classCounter++);
- // LinkedHashMap<String, Object> posgroup =
- // makePosition(null);
- LinkedHashMap<String, Object> posGroup = KoralObjectGenerator
- .makeGroup("position");
- LinkedHashMap<String, Object> positionOptions;
- // posgroup
- if (nodeCat.equals("OPIN")) {
- positionOptions = parseOPINOptions(node);
- }
- else {
- positionOptions = parseOPOVOptions(node);
- }
- posGroup.put("frames", positionOptions.get("frames"));
- posGroup.put("frame", positionOptions.get("frame"));
- if (positionOptions.containsKey("exclude")) {
- posGroup.put("exclude", positionOptions.get("exclude"));
- }
- objectStack.push(posGroup);
- // mark this an inverted operands object
- invertedOperandsLists.push((ArrayList<Object>) posGroup.get("operands"));
- stackedObjects++;
- // Step II: wrap in classRefCheck and/or focus and decide where to put
- ArrayList<String> check =
- (ArrayList<String>) positionOptions.get("classRefCheck");
- Integer[] classIn =
- new Integer[] { classCounter+128-2, classCounter+128-1 };
- LinkedHashMap<String, Object> topGroup;
- if (! check.isEmpty()) {
- // wrap position in a classRefCheck
- topGroup =
- KoralObjectGenerator.makeClassRefCheck(check, classIn,
- classCounter+128);
- ((ArrayList<Object>) topGroup.get("operands")).add(posGroup);
- } else {
- topGroup = posGroup;
- }
- LinkedHashMap<String, Object> focusGroup = null;
- if ((boolean) positionOptions.get("matchall") == true) {
- focusGroup = KoralObjectGenerator.makeClassRefOp("classRefOp:delete",
- new Integer[]{128+classCounter++}, 128+classCounter);
- ((ArrayList<Object>) focusGroup.get("operands")).add(topGroup);
- }
- else { // match only first argument
- focusGroup = KoralObjectGenerator.wrapInReference(topGroup,
- classCounter+128-1);
- classCounter++;
- }
- // wrap in 'merge' operation if grouping option is set
- if (positionOptions.containsKey("grouping")) {
- if (positionOptions.get("grouping").equals(true)) {
- LinkedHashMap<String, Object> mergeOperation =
- KoralObjectGenerator.makeGroup("merge");
- ArrayList<Object> mergeOperands = (ArrayList<Object>) mergeOperation.get("operands");
- mergeOperands.add(focusGroup);
- focusGroup = mergeOperation;
- }
- }
- putIntoSuperObject(focusGroup, 1);
- }
-
- @SuppressWarnings("unchecked")
- private void processOPPROX(Tree node) {
- // collect info
- Tree prox_opts = node.getChild(0);
- Tree typ = prox_opts.getChild(0);
- Tree dist_list = prox_opts.getChild(1);
- // Step I: create group
- LinkedHashMap<String, Object> group = KoralObjectGenerator
- .makeGroup("sequence");
-
- ArrayList<Object> constraints = new ArrayList<Object>();
- boolean exclusion = typ.getChild(0).toStringTree().equals("EXCL");
-
- boolean inOrder = false;
- boolean invertedOperands = false;
-
- group.put("inOrder", inOrder);
- group.put("distances", constraints);
-
- boolean putIntoOverlapDisjunction = false;
-
- int min = 0, max = 0;
- // possibly several distance constraints
- for (int i = 0; i < dist_list.getChildCount(); i++) {
- String direction = dist_list.getChild(i).getChild(0).getChild(0)
- .toStringTree().toLowerCase();
- String minStr = dist_list.getChild(i).getChild(1).getChild(0)
- .toStringTree();
- String maxStr = dist_list.getChild(i).getChild(1).getChild(1)
- .toStringTree();
- String meas = dist_list.getChild(i).getChild(2).getChild(0)
- .toStringTree();
- if (minStr.equals("VAL0")) {
- minStr = "0";
- }
- min = Integer.parseInt(minStr);
- max = Integer.parseInt(maxStr);
- // If zero word-distance, wrap this sequence in a
- // disjunction along with an overlap position
- // between the two operands
- /*
- * XXX: This is currently deactivated. Uncomment to
- * activate treatment of zero-word distances as
- * overlap-alternatives (see google doc on special
- * distances serialization)
- *
- * if (meas.equals("w") && min == 0) { min = 1;
- * putIntoOverlapDisjunction = true; }
- */
- if (!meas.equals("w") && min == 0) {
- processSpanDistance(meas, min, max);
- }
- LinkedHashMap<String, Object> distance = KoralObjectGenerator
- .makeDistance(meas, min, max);
- if (exclusion) {
- distance.put("exclude", true);
- }
- // if (! openNodeCats.get(1).equals("OPNHIT")) {
- constraints.add(distance);
- // }
- if (i == 0) {
- if (direction.equals("plus")) {
- inOrder = true;
- }
- else if (direction.equals("minus")) {
- inOrder = true;
- invertedOperands = true;
- }
- else if (direction.equals("both")) {
- inOrder = false;
- }
- }
- }
- group.put("inOrder", inOrder);
- LinkedHashMap<String, Object> embeddedSequence = group;
-
- if (!(openNodeCats.get(1).equals("OPBEG")
- || openNodeCats.get(1).equals("OPEND")
- || inOPALL
- || openNodeCats.get(1).equals("OPNHIT"))) {
- wrapOperandInClass(node, 1, 128+classCounter);
- wrapOperandInClass(node, 2, 128+classCounter);
- // Deactivated, uncomment to wrap sequence in reference.
- // group = KoralObjectGenerator.wrapInReference(group,
- // classCounter++);
- classCounter++;
- }
- else if (openNodeCats.get(1).equals("OPNHIT")) {
- LinkedHashMap<String, Object> repetition = KoralObjectGenerator
- .makeRepetition(min, max);
- ((ArrayList<Object>) repetition.get("operands"))
- .add(KoralObjectGenerator.makeToken());
- // TODO go on with this: put the repetition into a class
- // and put it in between the operands
- // -> what if there's several distance constraints. with
- // different keys, like /w4,s0?
- }
-
- // LinkedHashMap<String, Object> sequence = null;
- // if (putIntoOverlapDisjunction) {
- // sequence = embeddedSequence;
- // group = KoralObjectGenerator.makeGroup("or");
- // ArrayList<Object> disjOperands =
- // (ArrayList<Object>) group.get("operands");
- // LinkedHashMap<String, Object> overlapsGroup = KoralObjectGenerator
- // .makePosition(new String[0]);
- //
- // ArrayList<Object> overlapsOperands =
- // (ArrayList<Object>) overlapsGroup.get("operands");
- // // this ensures identity of the operands lists and thereby
- // // a distribution of the operands for both created objects
- // sequence.put("operands", overlapsOperands);
- // if (invertedOperands) {
- // invertedOperandsLists.push(overlapsOperands);
- // }
- // disjOperands.add(overlapsGroup);
- // disjOperands.add(KoralObjectGenerator.wrapInReference(sequence, 0));
- // // Step II: decide where to put
- // putIntoSuperObject(group, 0);
- // objectStack.push(sequence);
- // }
- // else {
- if (invertedOperands) {
- ArrayList<Object> operands =
- (ArrayList<Object>) embeddedSequence.get("operands");
- invertedOperandsLists.push(operands);
- }
- // Step II: decide where to put
- putIntoSuperObject(group, 0);
- objectStack.push(embeddedSequence);
- // }
- stackedObjects++;
- visited.add(node.getChild(0));
- }
-
- private void processOPOR(Tree node) {
- // Step I: create group
- LinkedHashMap<String, Object> disjunction =
- KoralObjectGenerator.makeGroup("disjunction");
- objectStack.push(disjunction);
- stackedObjects++;
- // Step II: decide where to put
- putIntoSuperObject(disjunction, 1);
- }
-
- private void processOPAND_OPNOT(Tree node) {
- // Step I: create group
- String nodeCat = getNodeCat(node);
- LinkedHashMap<String, Object> distgroup = KoralObjectGenerator.makeGroup("sequence");
- ArrayList<Object> distances = new ArrayList<Object>();
- LinkedHashMap<String, Object> zerodistance = KoralObjectGenerator.makeDistance("t", 0, 0);
- zerodistance.put("@type", "cosmas:distance"); // overwrite @type: cosmas:distance!
- if (nodeCat.equals("OPNOT"))
- zerodistance.put("exclude", true);
- distances.add(zerodistance);
- distgroup.put("distances", distances);
- distgroup.put("operands", new ArrayList<Object>());
- objectStack.push(distgroup);
- stackedObjects++;
- // Step II: decide where to put
- putIntoSuperObject(distgroup, 1);
- }
-
- private void processOPLABEL(Tree node) {
- // Step I: create element
- String key = node.getChild(0).toStringTree().replaceAll("<|>", "");
- LinkedHashMap<String, Object> elem = KoralObjectGenerator.makeSpan(key);
- // Step II: decide where to put
- putIntoSuperObject(elem);
- }
-
- @SuppressWarnings("unchecked")
- private void processOPELEM(Tree node) {
- // Step I: create element
- LinkedHashMap<String, Object> span = KoralObjectGenerator.makeSpan();
- if (node.getChild(0).toStringTree().equals("EMPTY")) {
- addError(StatusCodes.MALFORMED_QUERY, "Empty #ELEM() operator."
- + " Please specify a valid element key (like 's' for sentence).");
- return;
- }
- else {
- int elname = 0;
- Tree elnameNode = getFirstChildWithCat(node, "ELNAME");
- if (elnameNode != null) {
- span.put("key", elnameNode.getChild(0).toStringTree()
- .toLowerCase());
- elname = 1;
- }
- if (node.getChildCount() > elname) {
- /*
- * Attributes can carry several values, like #ELEM(W
- * ANA != 'N V'), denoting a word whose POS is neither
- * N nor V. When seeing this, create a sub-termGroup
- * and put it into the top-level term group, but only
- * if there are other attributes in that group. If
- * not, put the several values as distinct
- * attr-val-pairs into the top-level group (in order
- * to avoid a top-level group that only contains a
- * sub-group).
- */
- LinkedHashMap<String, Object> termGroup =
- KoralObjectGenerator.makeTermGroup("and");
- ArrayList<Object> termGroupOperands =
- (ArrayList<Object>) termGroup.get("operands");
- for (int i = elname; i < node.getChildCount(); i++) {
- Tree attrNode = node.getChild(i);
- if (attrNode.getChildCount() == 2) {
- LinkedHashMap<String, Object> term =
- KoralObjectGenerator.makeTerm();
+ LinkedHashMap<String, Object> subTermGroup = KoralObjectGenerator
+ .makeTermGroup("and");
+ ArrayList<Object> subTermGroupOperands = (ArrayList<Object>) subTermGroup
+ .get("operands");
+ int j;
+ for (j = 1; j < attrNode.getChildCount(); j++) {
+ LinkedHashMap<String, Object> term = KoralObjectGenerator
+ .makeTerm();
+ String layer = attrNode.getChild(0).toStringTree();
+ String[] splitted = layer.split("/");
+ if (splitted.length > 1) {
+ term.put("foundry", splitted[0]);
+ layer = splitted[1];
+ }
+ term.put("layer", translateMorph(layer));
+ term.put("key", attrNode.getChild(j).toStringTree());
+ String match = getNodeCat(attrNode).equals("EQ") ? "eq"
+ : "ne";
+ term.put("match", "match:" + match);
+ if (node.getChildCount() == elname + 1) {
termGroupOperands.add(term);
- String layer = attrNode.getChild(0).toStringTree();
- String[] splitted = layer.split("/");
- if (splitted.length > 1) {
- term.put("foundry", splitted[0]);
- layer = splitted[1];
- }
- term.put("layer", translateMorph(layer));
- term.put("key", attrNode.getChild(1).toStringTree());
- String match = getNodeCat(attrNode).equals("EQ") ? "eq":"ne";
- term.put("match", "match:" + match);
}
else {
- LinkedHashMap<String, Object> subTermGroup =
- KoralObjectGenerator.makeTermGroup("and");
- ArrayList<Object> subTermGroupOperands =
- (ArrayList<Object>) subTermGroup.get("operands");
- int j;
- for (j = 1; j < attrNode.getChildCount(); j++) {
- LinkedHashMap<String, Object> term =
- KoralObjectGenerator.makeTerm();
- String layer = attrNode.getChild(0).toStringTree();
- String[] splitted = layer.split("/");
- if (splitted.length > 1) {
- term.put("foundry", splitted[0]);
- layer = splitted[1];
- }
- term.put("layer", translateMorph(layer));
- term.put("key", attrNode.getChild(j).toStringTree());
- String match =
- getNodeCat(attrNode).equals("EQ") ? "eq" : "ne";
- term.put("match", "match:" + match);
- if (node.getChildCount() == elname + 1) {
- termGroupOperands.add(term);
- }
- else {
- subTermGroupOperands.add(term);
- }
- }
- if (node.getChildCount() > elname + 1) {
- termGroupOperands.add(subTermGroup);
- }
+ subTermGroupOperands.add(term);
}
- if (getNodeCat(attrNode).equals("NOTEQ"))
- negate = true;
}
- // possibly only one term was present throughout all
- // nodes: extract it from the group
- if (termGroupOperands.size() == 1) {
- termGroup = (LinkedHashMap<String, Object>)
- termGroupOperands.get(0);
+ if (node.getChildCount() > elname + 1) {
+ termGroupOperands.add(subTermGroup);
}
- span.put("attr", termGroup);
}
+ if (getNodeCat(attrNode).equals("NOTEQ"))
+ negate = true;
}
- // Step II: decide where to put
- putIntoSuperObject(span);
+ // possibly only one term was present throughout all
+ // nodes: extract it from the group
+ if (termGroupOperands.size() == 1) {
+ termGroup = (LinkedHashMap<String, Object>) termGroupOperands
+ .get(0);
+ }
+ span.put("attr", termGroup);
+ }
+ }
+ // Step II: decide where to put
+ putIntoSuperObject(span);
+ }
+
+
+ private void processOPMORPH (Tree node) {
+ // Step I: get info
+ String[] morphterms = node.getChild(0).toStringTree().replace(" ", "")
+ .split("&");
+ LinkedHashMap<String, Object> token = KoralObjectGenerator.makeToken();
+ ArrayList<Object> terms = new ArrayList<Object>();
+ LinkedHashMap<String, Object> fieldMap = null;
+ // regex group #2 is foundry, #4 layer, #5 operator,
+ // #6 key, #8 value
+ String wordOrRegex = "\\w+|\".+?\"";
+ Pattern p = Pattern.compile("((\\w+)/)?((\\w*)(!?=))?(" + wordOrRegex
+ + ")(:(" + wordOrRegex + "))?");
+ Matcher m;
+ for (String morphterm : morphterms) {
+ m = p.matcher(morphterm);
+ if (!m.matches()) {
+ addError(StatusCodes.INCOMPATIBLE_OPERATOR_AND_OPERAND,
+ "Something went wrong parsing the argument in MORPH().");
+ requestMap.put("query", new LinkedHashMap<String, Object>());
+ return;
}
- private void processOPMORPH(Tree node) {
- // Step I: get info
- String[] morphterms =
- node.getChild(0).toStringTree().replace(" ", "").split("&");
- LinkedHashMap<String, Object> token = KoralObjectGenerator.makeToken();
- ArrayList<Object> terms = new ArrayList<Object>();
- LinkedHashMap<String, Object> fieldMap = null;
- // regex group #2 is foundry, #4 layer, #5 operator,
- // #6 key, #8 value
- String wordOrRegex = "\\w+|\".+?\"";
- Pattern p = Pattern
- .compile("((\\w+)/)?((\\w*)(!?=))?("+wordOrRegex+")(:("+wordOrRegex+"))?");
- Matcher m;
- for (String morphterm : morphterms) {
- m = p.matcher(morphterm);
- if (!m.matches()) {
- addError(StatusCodes.INCOMPATIBLE_OPERATOR_AND_OPERAND,
- "Something went wrong parsing the argument in MORPH().");
- requestMap.put("query", new LinkedHashMap<String, Object>());
- return;
- }
+ fieldMap = KoralObjectGenerator.makeTerm();
- fieldMap = KoralObjectGenerator.makeTerm();
-
- if (m.group(2) != null)
- fieldMap.put("foundry", m.group(2));
- if (m.group(4) != null)
- fieldMap.put("layer", m.group(4));
- if (m.group(5) != null) {
- if ("!=".equals(m.group(5)))
- negate = !negate;
- }
- if (m.group(6) != null) {
- String key = m.group(6);
- if (key.startsWith("\"") && key.endsWith("\"")) {
- key = key.substring(1, key.length()-1);
- fieldMap.put("type", "type:regex");
- }
- fieldMap.put("key", key);
- }
-
- if (m.group(8) != null) {
- String value = m.group(8);
- if (value.startsWith("\"") && value.endsWith("\"")) {
- value = value.substring(1, value.length()-1);
- fieldMap.put("type", "type:regex");
- }
- fieldMap.put("value", value);
- }
-
- // negate field (see above)
- if (negate) {
- fieldMap.put("match", "match:ne");
- }
- else {
- fieldMap.put("match", "match:eq");
- }
- terms.add(fieldMap);
+ if (m.group(2) != null)
+ fieldMap.put("foundry", m.group(2));
+ if (m.group(4) != null)
+ fieldMap.put("layer", m.group(4));
+ if (m.group(5) != null) {
+ if ("!=".equals(m.group(5)))
+ negate = !negate;
+ }
+ if (m.group(6) != null) {
+ String key = m.group(6);
+ if (key.startsWith("\"") && key.endsWith("\"")) {
+ key = key.substring(1, key.length() - 1);
+ fieldMap.put("type", "type:regex");
}
- if (morphterms.length == 1) {
- token.put("wrap", fieldMap);
- }
- else {
- LinkedHashMap<String, Object> termGroup =
- KoralObjectGenerator.makeTermGroup("and");
- termGroup.put("operands", terms);
- token.put("wrap", termGroup);
- }
- // Step II: decide where to put
- putIntoSuperObject(token, 0);
- visited.add(node.getChild(0));
+ fieldMap.put("key", key);
}
- /**
- * Nodes introducing tokens. Process all in the same manner,
- * except for the fieldMap entry
- *
- * @param node
- */
- private void processOPWF_OPLEM(Tree node) {
- String nodeCat = getNodeCat(node);
- // Step I: get info
- LinkedHashMap<String, Object> token = KoralObjectGenerator.makeToken();
- objectStack.push(token);
- stackedObjects++;
- LinkedHashMap<String, Object> fieldMap =
- KoralObjectGenerator.makeTerm();
- token.put("wrap", fieldMap);
- // make category-specific fieldMap entry
- String attr = nodeCat.equals("OPWF") ? "orth" : "lemma";
- String value = node.getChild(0).toStringTree().replaceAll("\"", "");
- // check for wildcard string
- Pattern p = Pattern.compile("[+*?]");
- Matcher m = p.matcher(value);
- if (m.find())
- fieldMap.put("type", "type:wildcard");
-
- if (value.startsWith("$")) {
- value = value.substring(1);
- ArrayList<String> flags = new ArrayList<String>();
- flags.add("flags:caseInsensitive");
- fieldMap.put("flags", flags);
+ if (m.group(8) != null) {
+ String value = m.group(8);
+ if (value.startsWith("\"") && value.endsWith("\"")) {
+ value = value.substring(1, value.length() - 1);
+ fieldMap.put("type", "type:regex");
}
-
- fieldMap.put("key", value);
- fieldMap.put("layer", attr);
-
- // negate field (see above)
- if (negate) {
- fieldMap.put("match", "match:ne");
- }
- else {
- fieldMap.put("match", "match:eq");
- }
- // Step II: decide where to put
- if (!hasChild(node, "TPOS")) {
- putIntoSuperObject(token, 1);
- visited.add(node.getChild(0));
- }
- else {
- // TODO
- }
+ fieldMap.put("value", value);
}
- private void processSpanDistance(String meas, int min, int max) {
- // Do stuff here in case we'll decide one day to treat span distances
- // in a special way (see GDoc Special Distances Serialization).
+ // negate field (see above)
+ if (negate) {
+ fieldMap.put("match", "match:ne");
}
-
- /**
- * Registers an entry in the {@link #operandWrap} table in order
- * to allow an operator's arguments (or only one of them) to be
- * wrapped in a class group.
- *
- * @param node
- * The operator node (parent node of the ARG1/ARG2
- * node)
- * @param arg
- * The argument number (1 or 2)
- * @param cls
- * The class id.
- */
- private void wrapOperandInClass(Tree node, int arg, int cls) {
- LinkedHashMap<String, Object> clsGroup =
- KoralObjectGenerator.makeSpanClass(cls);
- wrapOperand(node, arg, clsGroup);
+ else {
+ fieldMap.put("match", "match:eq");
}
+ terms.add(fieldMap);
+ }
+ if (morphterms.length == 1) {
+ token.put("wrap", fieldMap);
+ }
+ else {
+ LinkedHashMap<String, Object> termGroup = KoralObjectGenerator
+ .makeTermGroup("and");
+ termGroup.put("operands", terms);
+ token.put("wrap", termGroup);
+ }
+ // Step II: decide where to put
+ putIntoSuperObject(token, 0);
+ visited.add(node.getChild(0));
+ }
- /**
- * Registers an entry in the {@link #operandWrap} table in order
- * to allow an operator's arguments (or only one of them) to be
- * wrapped in an arbitrary object, e.g. a reference group.
- *
- * @param node
- * The operator node (parent node of the ARG1/ARG2
- * node)
- * @param arg
- * The argument number (1 or 2)
- * @param container
- * The object in whose operand list the argument shall
- * be wrapped.
- */
- private void wrapOperand(Tree node, int arg,
- LinkedHashMap<String, Object> container) {
- operandWrap.put(node, arg, container);
+
+ /**
+ * Nodes introducing tokens. Process all in the same manner,
+ * except for the fieldMap entry
+ *
+ * @param node
+ */
+ private void processOPWF_OPLEM (Tree node) {
+ String nodeCat = getNodeCat(node);
+ // Step I: get info
+ LinkedHashMap<String, Object> token = KoralObjectGenerator.makeToken();
+ objectStack.push(token);
+ stackedObjects++;
+ LinkedHashMap<String, Object> fieldMap = KoralObjectGenerator
+ .makeTerm();
+ token.put("wrap", fieldMap);
+ // make category-specific fieldMap entry
+ String attr = nodeCat.equals("OPWF") ? "orth" : "lemma";
+ String value = node.getChild(0).toStringTree().replaceAll("\"", "");
+ // check for wildcard string
+ Pattern p = Pattern.compile("[+*?]");
+ Matcher m = p.matcher(value);
+ if (m.find())
+ fieldMap.put("type", "type:wildcard");
+
+ if (value.startsWith("$")) {
+ value = value.substring(1);
+ ArrayList<String> flags = new ArrayList<String>();
+ flags.add("flags:caseInsensitive");
+ fieldMap.put("flags", flags);
+ }
+
+ fieldMap.put("key", value);
+ fieldMap.put("layer", attr);
+
+ // negate field (see above)
+ if (negate) {
+ fieldMap.put("match", "match:ne");
+ }
+ else {
+ fieldMap.put("match", "match:eq");
+ }
+ // Step II: decide where to put
+ if (!hasChild(node, "TPOS")) {
+ putIntoSuperObject(token, 1);
+ visited.add(node.getChild(0));
+ }
+ else {
+ // TODO
+ }
+ }
+
+
+ private void processSpanDistance (String meas, int min, int max) {
+ // Do stuff here in case we'll decide one day to treat span distances
+ // in a special way (see GDoc Special Distances Serialization).
+ }
+
+
+ /**
+ * Registers an entry in the {@link #operandWrap} table in order
+ * to allow an operator's arguments (or only one of them) to be
+ * wrapped in a class group.
+ *
+ * @param node
+ * The operator node (parent node of the ARG1/ARG2
+ * node)
+ * @param arg
+ * The argument number (1 or 2)
+ * @param cls
+ * The class id.
+ */
+ private void wrapOperandInClass (Tree node, int arg, int cls) {
+ LinkedHashMap<String, Object> clsGroup = KoralObjectGenerator
+ .makeSpanClass(cls);
+ wrapOperand(node, arg, clsGroup);
+ }
+
+
+ /**
+ * Registers an entry in the {@link #operandWrap} table in order
+ * to allow an operator's arguments (or only one of them) to be
+ * wrapped in an arbitrary object, e.g. a reference group.
+ *
+ * @param node
+ * The operator node (parent node of the ARG1/ARG2
+ * node)
+ * @param arg
+ * The argument number (1 or 2)
+ * @param container
+ * The object in whose operand list the argument shall
+ * be wrapped.
+ */
+ private void wrapOperand (Tree node, int arg,
+ LinkedHashMap<String, Object> container) {
+ operandWrap.put(node, arg, container);
+ }
+
+
+ private Object translateMorph (String layer) {
+ // might be extended...
+ if (layer.equals("ANA"))
+ return ResourceMapper.descriptor2policy("ANA");
+ else
+ return layer;
+
+ }
+
+
+ @SuppressWarnings("unchecked")
+ /**
+ * Processes individual position conditions as provided in the OPTS node under the OPBEG node.
+ * #BEG allows to specify position constrains that apply to the beginning or the end of the subquery X.
+ * E.g., in #BEG(X, tpos/tpos), the 'tpos' constraints before the slash indicate conditions that apply
+ * to the beginning of X, those after the slash are conditions that apply to the end of X.
+ * See the official C-II documentation for more details. <br/><br/>
+ * What's important here is what follows: <br/>
+ * Assume the query #BED(der Mann, sa/pa). This means that <b>the beginning<b/> of "der Mann" stands at
+ * the beginning of a sentence and that <b>the end</b> (because this constraint comes after the slash) stands at the
+ * beginning of a paragraph. The "end" means the last item, here "Mann", so this token comes at the beginning
+ * of a paragraph. To capture this, we choose spanRefs: The last item of X matches the first item of the span (here: P).
+ * @param cond
+ * @param distributedOperands
+ * @param mode
+ * @return
+ */
+ private LinkedHashMap<String, Object> processPositionCondition (Tree cond,
+ ArrayList<Object> distributedOperands, String mode) {
+ boolean negated = false;
+ String elem; // the 'span' (s/p/t)
+ String position = "frames:matches"; // default
+ // spanRef to be used for the element ('span')
+ Integer[] elemSpanRef = null;
+ // spanRef to be used for the subquery X
+ Integer[] hitSpanRef = null;
+
+ String nodeString = cond.toStringTree();
+ if (nodeString.startsWith("-")) {
+ negated = true;
+ nodeString = nodeString.substring(1);
+ }
+ else if (nodeString.startsWith("+")) {
+ nodeString = nodeString.substring(1);
+ }
+ elem = nodeString.substring(0, 1);
+ nodeString = nodeString.substring(1);
+ // in cases where the end of X shall match the beginning of
+ // the span, or vice versa,
+ // we need to define spanRefs
+ if (mode.equals("beg")) {
+ if (nodeString.equals("a")) {
+ position = "frames:startsWith";
}
-
- private Object translateMorph(String layer) {
- // might be extended...
- if (layer.equals("ANA"))
- return ResourceMapper.descriptor2policy("ANA");
- else
- return layer;
-
+ else if (nodeString.equals("e")) {
+ hitSpanRef = new Integer[] { 0, 1 };
+ elemSpanRef = new Integer[] { -1, 1 };
}
-
- @SuppressWarnings("unchecked")
- /**
- * Processes individual position conditions as provided in the OPTS node under the OPBEG node.
- * #BEG allows to specify position constrains that apply to the beginning or the end of the subquery X.
- * E.g., in #BEG(X, tpos/tpos), the 'tpos' constraints before the slash indicate conditions that apply
- * to the beginning of X, those after the slash are conditions that apply to the end of X.
- * See the official C-II documentation for more details. <br/><br/>
- * What's important here is what follows: <br/>
- * Assume the query #BED(der Mann, sa/pa). This means that <b>the beginning<b/> of "der Mann" stands at
- * the beginning of a sentence and that <b>the end</b> (because this constraint comes after the slash) stands at the
- * beginning of a paragraph. The "end" means the last item, here "Mann", so this token comes at the beginning
- * of a paragraph. To capture this, we choose spanRefs: The last item of X matches the first item of the span (here: P).
- * @param cond
- * @param distributedOperands
- * @param mode
- * @return
- */
- private LinkedHashMap<String, Object> processPositionCondition(Tree cond,
- ArrayList<Object> distributedOperands, String mode) {
- boolean negated = false;
- String elem; // the 'span' (s/p/t)
- String position = "frames:matches"; // default
- // spanRef to be used for the element ('span')
- Integer[] elemSpanRef = null;
- // spanRef to be used for the subquery X
- Integer[] hitSpanRef = null;
-
- String nodeString = cond.toStringTree();
- if (nodeString.startsWith("-")) {
- negated = true;
- nodeString = nodeString.substring(1);
- }
- else if (nodeString.startsWith("+")) {
- nodeString = nodeString.substring(1);
- }
- elem = nodeString.substring(0, 1);
- nodeString = nodeString.substring(1);
- // in cases where the end of X shall match the beginning of
- // the span, or vice versa,
- // we need to define spanRefs
- if (mode.equals("beg")) {
- if (nodeString.equals("a")) {
- position = "frames:startsWith";
- }
- else if (nodeString.equals("e")) {
- hitSpanRef = new Integer[] { 0, 1 };
- elemSpanRef = new Integer[] { -1, 1 };
- }
- }
- else if (mode.equals("end")) {
- if (nodeString.equals("e")) {
- position = "frames:endsWith";
- }
- else if (nodeString.equals("a")) {
- hitSpanRef = new Integer[] { 0, 1 };
- elemSpanRef = new Integer[] { -1, 1 };
- }
- }
- // Create the position group and add the span and the subquery
- // as operands, possibly wrapped in spanRefs
- LinkedHashMap<String, Object> positionGroup = KoralObjectGenerator
- .makePosition(new String[] { position });
- if (negated)
- positionGroup.put("exclude", true);
- ArrayList<Object> posOperands = new ArrayList<Object>();
- LinkedHashMap<String, Object> classGroup =
- KoralObjectGenerator.makeSpanClass(128+classCounter++);
- classGroup.put("operands", distributedOperands);
- positionGroup.put("operands", posOperands);
- LinkedHashMap<String, Object> span = KoralObjectGenerator.makeSpan(elem);
- objectStack.push(classGroup);
- if (hitSpanRef != null) {
- LinkedHashMap<String, Object> spanRefAroundHit =
- KoralObjectGenerator.makeSpanReference(hitSpanRef, "focus");
- ((ArrayList<Object>) spanRefAroundHit.get("operands"))
+ }
+ else if (mode.equals("end")) {
+ if (nodeString.equals("e")) {
+ position = "frames:endsWith";
+ }
+ else if (nodeString.equals("a")) {
+ hitSpanRef = new Integer[] { 0, 1 };
+ elemSpanRef = new Integer[] { -1, 1 };
+ }
+ }
+ // Create the position group and add the span and the subquery
+ // as operands, possibly wrapped in spanRefs
+ LinkedHashMap<String, Object> positionGroup = KoralObjectGenerator
+ .makePosition(new String[] { position });
+ if (negated)
+ positionGroup.put("exclude", true);
+ ArrayList<Object> posOperands = new ArrayList<Object>();
+ LinkedHashMap<String, Object> classGroup = KoralObjectGenerator
+ .makeSpanClass(128 + classCounter++);
+ classGroup.put("operands", distributedOperands);
+ positionGroup.put("operands", posOperands);
+ LinkedHashMap<String, Object> span = KoralObjectGenerator
+ .makeSpan(elem);
+ objectStack.push(classGroup);
+ if (hitSpanRef != null) {
+ LinkedHashMap<String, Object> spanRefAroundHit = KoralObjectGenerator
+ .makeSpanReference(hitSpanRef, "focus");
+ ((ArrayList<Object>) spanRefAroundHit.get("operands"))
.add(classGroup);
- // re-assign after wrapping classGroup in spanRef
- classGroup = spanRefAroundHit;
- }
- if (elemSpanRef != null) {
- LinkedHashMap<String, Object> spanRefAroundSpan =
- KoralObjectGenerator.makeSpanReference(elemSpanRef, "focus");
- ((ArrayList<Object>) spanRefAroundSpan.get("operands")).add(span);
- // re-assign after wrapping span in spanRef
- span = spanRefAroundSpan;
- }
- posOperands.add(span);
- posOperands.add(classGroup);
- return positionGroup;
+ // re-assign after wrapping classGroup in spanRef
+ classGroup = spanRefAroundHit;
+ }
+ if (elemSpanRef != null) {
+ LinkedHashMap<String, Object> spanRefAroundSpan = KoralObjectGenerator
+ .makeSpanReference(elemSpanRef, "focus");
+ ((ArrayList<Object>) spanRefAroundSpan.get("operands")).add(span);
+ // re-assign after wrapping span in spanRef
+ span = spanRefAroundSpan;
+ }
+ posOperands.add(span);
+ posOperands.add(classGroup);
+ return positionGroup;
+ }
+
+
+ private LinkedHashMap<String, Object> parseOPINOptions (Tree node) {
+ Tree posnode = getFirstChildWithCat(node, "POS");
+ Tree rangenode = getFirstChildWithCat(node, "RANGE");
+ Tree exclnode = getFirstChildWithCat(node, "EXCL");
+ Tree groupnode = getFirstChildWithCat(node, "GROUP");
+ boolean negatePosition = false;
+ LinkedHashMap<String, Object> posOptions = new LinkedHashMap<String, Object>();
+ ArrayList<String> positions = new ArrayList<String>();
+ ArrayList<String> classRefCheck = new ArrayList<String>();
+ posOptions.put("matchall", false);
+ String posOption = null;
+ if (posnode != null) {
+ posOption = posnode.getChild(0).toStringTree();
+ switch (posOption) {
+ case "L":
+ positions.add("frames:startsWith");
+ positions.add("frames:matches");
+ // classRefCheck.add("classRefCheck:includes");
+ break;
+ case "R":
+ positions.add("frames:endsWith");
+ positions.add("frames:matches");
+ // classRefCheck.add("classRefCheck:includes");
+ break;
+ case "F":
+ positions.add("frames:matches");
+ // classRefCheck.add("classRefCheck:includes");
+ break;
+ case "FE":
+ positions.add("frames:matches");
+ classRefCheck.add("classRefCheck:equals");
+ break;
+ case "FI":
+ positions.add("frames:matches");
+ classRefCheck.add("classRefCheck:unequals");
+ // classRefCheck.add("classRefCheck:includes");
+ break;
+ case "N":
+ positions.add("frames:contains");
+ // classRefCheck.add("classRefCheck:includes");
+ break;
}
-
- private LinkedHashMap<String, Object> parseOPINOptions(Tree node) {
- Tree posnode = getFirstChildWithCat(node, "POS");
- Tree rangenode = getFirstChildWithCat(node, "RANGE");
- Tree exclnode = getFirstChildWithCat(node, "EXCL");
- Tree groupnode = getFirstChildWithCat(node, "GROUP");
- boolean negatePosition = false;
- LinkedHashMap<String, Object> posOptions = new LinkedHashMap<String, Object>();
- ArrayList<String> positions = new ArrayList<String>();
- ArrayList<String> classRefCheck = new ArrayList<String>();
- posOptions.put("matchall", false);
- String posOption = null;
- if (posnode != null) {
- posOption = posnode.getChild(0).toStringTree();
- switch (posOption) {
- case "L":
- positions.add("frames:startsWith");
- positions.add("frames:matches");
- // classRefCheck.add("classRefCheck:includes");
- break;
- case "R":
- positions.add("frames:endsWith");
- positions.add("frames:matches");
- // classRefCheck.add("classRefCheck:includes");
- break;
- case "F":
- positions.add("frames:matches");
- // classRefCheck.add("classRefCheck:includes");
- break;
- case "FE":
- positions.add("frames:matches");
- classRefCheck.add("classRefCheck:equals");
- break;
- case "FI":
- positions.add("frames:matches");
- classRefCheck.add("classRefCheck:unequals");
- // classRefCheck.add("classRefCheck:includes");
- break;
- case "N":
- positions.add("frames:contains");
- // classRefCheck.add("classRefCheck:includes");
- break;
- }
- } else {
- classRefCheck.add("classRefCheck:includes");
- }
- posOptions.put("frames", positions);
- posOptions.put("classRefCheck", classRefCheck);
- if (exclnode != null) {
- if (exclnode.getChild(0).toStringTree().equals("YES")) {
- negatePosition = !negatePosition;
- }
- }
-
- if (rangenode != null) {
- String range = rangenode.getChild(0).toStringTree().toLowerCase();
- if (range.equals("all")) {
- posOptions.put("matchall", true);
- // LinkedHashMap<String,Object> ref =
- // makeResetReference(); // reset all defined classes
- // wrapOperand(node,2,ref);
- }
- }
-
- if (negatePosition) {
- posOptions.put("exclude", true);
- }
-
- boolean grouping = false;
- if (groupnode != null) {
- if (groupnode.getChild(0).toStringTree().equalsIgnoreCase("max")) {
- grouping = true;
- }
- }
- posOptions.put("grouping", grouping);
-
- return posOptions;
+ }
+ else {
+ classRefCheck.add("classRefCheck:includes");
+ }
+ posOptions.put("frames", positions);
+ posOptions.put("classRefCheck", classRefCheck);
+ if (exclnode != null) {
+ if (exclnode.getChild(0).toStringTree().equals("YES")) {
+ negatePosition = !negatePosition;
}
+ }
- private LinkedHashMap<String, Object> parseOPOVOptions(Tree node) {
- boolean negatePosition = false;
- Tree posnode = getFirstChildWithCat(node, "POS");
- Tree rangenode = getFirstChildWithCat(node, "RANGE");
- Tree exclnode = getFirstChildWithCat(node, "EXCL");
- Tree groupnode = getFirstChildWithCat(node, "GROUP");
- LinkedHashMap<String, Object> posOptions = new LinkedHashMap<String, Object>();
- ArrayList<String> positions = new ArrayList<String>();
- ArrayList<String> classRefCheck = new ArrayList<String>();
- posOptions.put("matchall", false);
- String posOption = null;
- if (posnode != null) {
- posOption = posnode.getChild(0).toStringTree();
- switch (posOption) {
- case "L":
- positions.add("frames:startsWith");
- positions.add("frames:overlapsLeft");
- positions.add("frames:matches");
- classRefCheck.add("classRefCheck:intersects");
- break;
- case "R":
- positions.add("frames:endsWith");
- positions.add("frames:overlapsRight");
- positions.add("frames:matches");
- classRefCheck.add("classRefCheck:intersects");
- break;
- case "F":
- positions.add("frames:matches");
- classRefCheck.add("classRefCheck:intersects");
- break;
- case "FE":
- positions.add("frames:matches");
- classRefCheck.add("classRefCheck:equals");
- break;
- case "FI":
- positions.add("frames:matches");
- classRefCheck.add("classRefCheck:unequals");
- break;
- case "X":
- positions.add("frames:contains");
- classRefCheck.add("classRefCheck:intersects");
- break;
- }
- }
- else {
+ if (rangenode != null) {
+ String range = rangenode.getChild(0).toStringTree().toLowerCase();
+ if (range.equals("all")) {
+ posOptions.put("matchall", true);
+ // LinkedHashMap<String,Object> ref =
+ // makeResetReference(); // reset all defined classes
+ // wrapOperand(node,2,ref);
+ }
+ }
+
+ if (negatePosition) {
+ posOptions.put("exclude", true);
+ }
+
+ boolean grouping = false;
+ if (groupnode != null) {
+ if (groupnode.getChild(0).toStringTree().equalsIgnoreCase("max")) {
+ grouping = true;
+ }
+ }
+ posOptions.put("grouping", grouping);
+
+ return posOptions;
+ }
+
+
+ private LinkedHashMap<String, Object> parseOPOVOptions (Tree node) {
+ boolean negatePosition = false;
+ Tree posnode = getFirstChildWithCat(node, "POS");
+ Tree rangenode = getFirstChildWithCat(node, "RANGE");
+ Tree exclnode = getFirstChildWithCat(node, "EXCL");
+ Tree groupnode = getFirstChildWithCat(node, "GROUP");
+ LinkedHashMap<String, Object> posOptions = new LinkedHashMap<String, Object>();
+ ArrayList<String> positions = new ArrayList<String>();
+ ArrayList<String> classRefCheck = new ArrayList<String>();
+ posOptions.put("matchall", false);
+ String posOption = null;
+ if (posnode != null) {
+ posOption = posnode.getChild(0).toStringTree();
+ switch (posOption) {
+ case "L":
+ positions.add("frames:startsWith");
+ positions.add("frames:overlapsLeft");
+ positions.add("frames:matches");
classRefCheck.add("classRefCheck:intersects");
- }
-
- posOptions.put("frames", positions);
- posOptions.put("classRefCheck", classRefCheck);
- if (exclnode != null) {
- if (exclnode.getChild(0).toStringTree().equals("YES")) {
- negatePosition = !negatePosition;
- }
- }
-
- if (rangenode != null) {
- String range = rangenode.getChild(0).toStringTree().toLowerCase();
- if (range.equals("all")) {
- posOptions.put("matchall", true);
- // LinkedHashMap<String,Object> ref =
- // makeResetReference(); // reset all defined classes
- // wrapOperand(node,2,ref);
- }
- }
-
- if (negatePosition) {
- posOptions.put("exclude", "true");
- }
-
- boolean grouping = false;
- if (groupnode != null) {
- if (groupnode.getChild(0).toStringTree().equalsIgnoreCase("max")) {
- grouping = true;
- }
- }
- posOptions.put("grouping", grouping);
-
- return posOptions;
+ break;
+ case "R":
+ positions.add("frames:endsWith");
+ positions.add("frames:overlapsRight");
+ positions.add("frames:matches");
+ classRefCheck.add("classRefCheck:intersects");
+ break;
+ case "F":
+ positions.add("frames:matches");
+ classRefCheck.add("classRefCheck:intersects");
+ break;
+ case "FE":
+ positions.add("frames:matches");
+ classRefCheck.add("classRefCheck:equals");
+ break;
+ case "FI":
+ positions.add("frames:matches");
+ classRefCheck.add("classRefCheck:unequals");
+ break;
+ case "X":
+ positions.add("frames:contains");
+ classRefCheck.add("classRefCheck:intersects");
+ break;
}
+ }
+ else {
+ classRefCheck.add("classRefCheck:intersects");
+ }
- @SuppressWarnings({ "unchecked" })
- private LinkedHashMap<String, Object> wrap(LinkedHashMap<String, Object>[] wrapCascade) {
- int i;
- for (i = 0; i < wrapCascade.length - 1; i++) {
- ArrayList<Object> containerOperands = (ArrayList<Object>) wrapCascade[i + 1]
- .get("operands");
- containerOperands.add(0, wrapCascade[i]);
- }
- return wrapCascade[i];
+ posOptions.put("frames", positions);
+ posOptions.put("classRefCheck", classRefCheck);
+ if (exclnode != null) {
+ if (exclnode.getChild(0).toStringTree().equals("YES")) {
+ negatePosition = !negatePosition;
}
+ }
- @SuppressWarnings("unchecked")
- private void putIntoSuperObject(LinkedHashMap<String, Object> object,
- int objStackPosition) {
- if (objectStack.size() > objStackPosition) {
- ArrayList<Object> topObjectOperands = (ArrayList<Object>) objectStack
- .get(objStackPosition).get("operands");
- if (!invertedOperandsLists.contains(topObjectOperands)) {
- topObjectOperands.add(object);
- }
- else {
- topObjectOperands.add(0, object);
- }
- }
- else {
- requestMap.put("query", object);
- }
+ if (rangenode != null) {
+ String range = rangenode.getChild(0).toStringTree().toLowerCase();
+ if (range.equals("all")) {
+ posOptions.put("matchall", true);
+ // LinkedHashMap<String,Object> ref =
+ // makeResetReference(); // reset all defined classes
+ // wrapOperand(node,2,ref);
}
+ }
- private void putIntoSuperObject(LinkedHashMap<String, Object> object) {
- putIntoSuperObject(object, 0);
+ if (negatePosition) {
+ posOptions.put("exclude", "true");
+ }
+
+ boolean grouping = false;
+ if (groupnode != null) {
+ if (groupnode.getChild(0).toStringTree().equalsIgnoreCase("max")) {
+ grouping = true;
}
+ }
+ posOptions.put("grouping", grouping);
- /**
- * Normalises position operators to equivalents using #BED
- */
- private String rewritePositionQuery(String q) {
- Pattern p = Pattern.compile("(\\w+):((\\+|-)?(sa|se|pa|pe|ta|te),?)+");
- Matcher m = p.matcher(q);
+ return posOptions;
+ }
- String rewrittenQuery = q;
- while (m.find()) {
- String match = m.group();
- String conditionsString = match.split(":")[1];
- Pattern conditionPattern = Pattern
- .compile("(\\+|-)?(sa|se|pa|pe|ta|te)");
- Matcher conditionMatcher = conditionPattern
- .matcher(conditionsString);
- String replacement = "#BED(" + m.group(1) + " , ";
- while (conditionMatcher.find()) {
- replacement = replacement + conditionMatcher.group() + ",";
- }
- // remove trailing comma and close parenthesis
- replacement =
- replacement.substring(0, replacement.length() - 1)+ ")";
- rewrittenQuery = rewrittenQuery.replace(match, replacement);
- }
- return rewrittenQuery;
+
+ @SuppressWarnings({ "unchecked" })
+ private LinkedHashMap<String, Object> wrap (
+ LinkedHashMap<String, Object>[] wrapCascade) {
+ int i;
+ for (i = 0; i < wrapCascade.length - 1; i++) {
+ ArrayList<Object> containerOperands = (ArrayList<Object>) wrapCascade[i + 1]
+ .get("operands");
+ containerOperands.add(0, wrapCascade[i]);
+ }
+ return wrapCascade[i];
+ }
+
+
+ @SuppressWarnings("unchecked")
+ private void putIntoSuperObject (LinkedHashMap<String, Object> object,
+ int objStackPosition) {
+ if (objectStack.size() > objStackPosition) {
+ ArrayList<Object> topObjectOperands = (ArrayList<Object>) objectStack
+ .get(objStackPosition).get("operands");
+ if (!invertedOperandsLists.contains(topObjectOperands)) {
+ topObjectOperands.add(object);
}
-
- private Tree parseCosmasQuery(String query) {
- query = rewritePositionQuery(query);
- Tree tree = null;
- Antlr3DescriptiveErrorListener errorListener =
- new Antlr3DescriptiveErrorListener(query);
- try {
- ANTLRStringStream ss = new ANTLRStringStream(query);
- c2psLexer lex = new c2psLexer(ss);
- org.antlr.runtime.CommonTokenStream tokens =
- new org.antlr.runtime.CommonTokenStream(lex); // v3
- parser = new c2psParser(tokens);
- // Use custom error reporters
- lex.setErrorReporter(errorListener);
- ((c2psParser) parser).setErrorReporter(errorListener);
- c2psParser.c2ps_query_return c2Return = ((c2psParser) parser)
- .c2ps_query(); // statt t().
- // AST Tree anzeigen:
- tree = (Tree) c2Return.getTree();
-
- }
- catch (RecognitionException e) {
- log.error("Could not parse query. Please make sure it is well-formed.");
- addError(StatusCodes.MALFORMED_QUERY,
- "Could not parse query. Please make sure it is well-formed.");
- }
- String treestring = tree.toStringTree();
-
- boolean erroneous = false;
- if (parser.failed() || parser.getNumberOfSyntaxErrors() > 0) {
- erroneous = true;
- tree = null;
- }
-
- if (erroneous || treestring.contains("<mismatched token")
- || treestring.contains("<error")
- || treestring.contains("<unexpected")) {
- log.error(errorListener.generateFullErrorMsg().toString());
- addError(errorListener.generateFullErrorMsg());
- }
- return tree;
+ else {
+ topObjectOperands.add(0, object);
}
+ }
+ else {
+ requestMap.put("query", object);
+ }
+ }
+
+
+ private void putIntoSuperObject (LinkedHashMap<String, Object> object) {
+ putIntoSuperObject(object, 0);
+ }
+
+
+ /**
+ * Normalises position operators to equivalents using #BED
+ */
+ private String rewritePositionQuery (String q) {
+ Pattern p = Pattern.compile("(\\w+):((\\+|-)?(sa|se|pa|pe|ta|te),?)+");
+ Matcher m = p.matcher(q);
+
+ String rewrittenQuery = q;
+ while (m.find()) {
+ String match = m.group();
+ String conditionsString = match.split(":")[1];
+ Pattern conditionPattern = Pattern
+ .compile("(\\+|-)?(sa|se|pa|pe|ta|te)");
+ Matcher conditionMatcher = conditionPattern
+ .matcher(conditionsString);
+ String replacement = "#BED(" + m.group(1) + " , ";
+ while (conditionMatcher.find()) {
+ replacement = replacement + conditionMatcher.group() + ",";
+ }
+ // remove trailing comma and close parenthesis
+ replacement = replacement.substring(0, replacement.length() - 1)
+ + ")";
+ rewrittenQuery = rewrittenQuery.replace(match, replacement);
+ }
+ return rewrittenQuery;
+ }
+
+
+ private Tree parseCosmasQuery (String query) {
+ query = rewritePositionQuery(query);
+ Tree tree = null;
+ Antlr3DescriptiveErrorListener errorListener = new Antlr3DescriptiveErrorListener(
+ query);
+ try {
+ ANTLRStringStream ss = new ANTLRStringStream(query);
+ c2psLexer lex = new c2psLexer(ss);
+ org.antlr.runtime.CommonTokenStream tokens = new org.antlr.runtime.CommonTokenStream(
+ lex); // v3
+ parser = new c2psParser(tokens);
+ // Use custom error reporters
+ lex.setErrorReporter(errorListener);
+ ((c2psParser) parser).setErrorReporter(errorListener);
+ c2psParser.c2ps_query_return c2Return = ((c2psParser) parser)
+ .c2ps_query(); // statt t().
+ // AST Tree anzeigen:
+ tree = (Tree) c2Return.getTree();
+
+ }
+ catch (RecognitionException e) {
+ log.error("Could not parse query. Please make sure it is well-formed.");
+ addError(StatusCodes.MALFORMED_QUERY,
+ "Could not parse query. Please make sure it is well-formed.");
+ }
+ String treestring = tree.toStringTree();
+
+ boolean erroneous = false;
+ if (parser.failed() || parser.getNumberOfSyntaxErrors() > 0) {
+ erroneous = true;
+ tree = null;
+ }
+
+ if (erroneous || treestring.contains("<mismatched token")
+ || treestring.contains("<error")
+ || treestring.contains("<unexpected")) {
+ log.error(errorListener.generateFullErrorMsg().toString());
+ addError(errorListener.generateFullErrorMsg());
+ }
+ return tree;
+ }
}
\ No newline at end of file
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/CqlQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/CqlQueryProcessor.java
index 6ed5f6b..b06731c 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/CqlQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/CqlQueryProcessor.java
@@ -35,16 +35,19 @@
private String version;
private boolean isCaseSensitive; // default true
+
public CqlQueryProcessor (String query) {
this(query, VERSION_1_2, true);
}
+
public CqlQueryProcessor (String query, String version) {
this(query, version, true);
}
+
public CqlQueryProcessor (String query, String version,
- boolean isCaseSensitive) {
+ boolean isCaseSensitive) {
this.version = version;
this.isCaseSensitive = isCaseSensitive;
this.requestMap = new LinkedHashMap<>();
@@ -52,13 +55,15 @@
process(query);
}
+
@Override
- public Map<String, Object> getRequestMap() {
+ public Map<String, Object> getRequestMap () {
return this.requestMap;
}
+
@Override
- public void process(String query) {
+ public void process (String query) {
if ((query == null) || query.isEmpty())
addError(StatusCodes.MALFORMED_QUERY,
"SRU diagnostic 27: An empty query is unsupported.");
@@ -69,7 +74,8 @@
// requestMap.put("query", sentenceWrapper(queryMap));
}
- private Map<String, Object> sentenceWrapper(Map<String, Object> m) {
+
+ private Map<String, Object> sentenceWrapper (Map<String, Object> m) {
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("@type", "koral:group");
map.put("operation", OPERATION_POSITION);
@@ -87,7 +93,8 @@
return map;
}
- private CQLNode parseQuerytoCQLNode(String query) {
+
+ private CQLNode parseQuerytoCQLNode (String query) {
try {
int compat = -1;
switch (version) {
@@ -106,7 +113,8 @@
}
}
- private Map<String, Object> parseCQLNode(CQLNode node) {
+
+ private Map<String, Object> parseCQLNode (CQLNode node) {
if (node instanceof CQLTermNode) {
return parseTermNode((CQLTermNode) node);
@@ -126,7 +134,8 @@
}
}
- private Map<String, Object> parseTermNode(CQLTermNode node) {
+
+ private Map<String, Object> parseTermNode (CQLTermNode node) {
checkTermNode(node);
final String term = node.getTerm();
if ((term == null) || term.isEmpty()) {
@@ -142,7 +151,8 @@
}
}
- private Map<String, Object> parseAndNode(CQLAndNode node) {
+
+ private Map<String, Object> parseAndNode (CQLAndNode node) {
checkBooleanModifier(node);
Map<String, Object> map = new LinkedHashMap<String, Object>();
@@ -167,7 +177,8 @@
return map;
}
- private Map<String, Object> parseOrNode(CQLOrNode node) {
+
+ private Map<String, Object> parseOrNode (CQLOrNode node) {
checkBooleanModifier(node);
Map<String, Object> map = new LinkedHashMap<String, Object>();
@@ -182,7 +193,8 @@
return map;
}
- private Map<String, Object> writeSequence(String str) {
+
+ private Map<String, Object> writeSequence (String str) {
Map<String, Object> sequenceMap = new LinkedHashMap<String, Object>();
sequenceMap.put("@type", "koral:group");
sequenceMap.put("operation", OPERATION_SEQUENCE);
@@ -197,7 +209,8 @@
return sequenceMap;
}
- private Map<String, Object> writeTerm(String term) {
+
+ private Map<String, Object> writeTerm (String term) {
Map<String, Object> map = new LinkedHashMap<String, Object>();
map.put("@type", "koral:term");
if (!isCaseSensitive) {
@@ -213,7 +226,8 @@
return tokenMap;
}
- private void checkBooleanModifier(CQLBooleanNode node) {
+
+ private void checkBooleanModifier (CQLBooleanNode node) {
List<Modifier> modifiers = node.getModifiers();
if ((modifiers != null) && !modifiers.isEmpty()) {
Modifier modifier = modifiers.get(0);
@@ -223,7 +237,8 @@
}
}
- private void checkTermNode(CQLTermNode node) {
+
+ private void checkTermNode (CQLTermNode node) {
// only allow "cql.serverChoice" and "words" index
if (!(INDEX_CQL_SERVERCHOICE.equals(node.getIndex()) || INDEX_WORDS
.equals(node.getIndex()))) {
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/DummyQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/DummyQueryProcessor.java
index 5ce7a0c..e6ad629 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/DummyQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/DummyQueryProcessor.java
@@ -7,12 +7,12 @@
* instatiating a class, errors/warnings cannot be reported.
*
* @author bingel
- *
+ *
*/
public final class DummyQueryProcessor extends AbstractQueryProcessor {
@Override
- public void process(String query) {
+ public void process (String query) {
// This is just a dummy class. Do nothing!
}
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/IdWriter.java b/src/main/java/de/ids_mannheim/korap/query/serialize/IdWriter.java
index 966b3d3..d9302aa 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/IdWriter.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/IdWriter.java
@@ -10,8 +10,8 @@
/**
* @author hanl
* @date 04/06/2014
- * <p/>
- * create idn for korap:token
+ * <p/>
+ * create idn for korap:token
*/
public class IdWriter {
@@ -19,17 +19,20 @@
private int counter;
private ObjectMapper mapper = new ObjectMapper();
- public IdWriter(String json) {
+
+ public IdWriter (String json) {
node = mapper.valueToTree(json);
counter = 0;
}
- public IdWriter process() {
+
+ public IdWriter process () {
process(node.path("query"));
return this;
}
- private void process(JsonNode node) {
+
+ private void process (JsonNode node) {
if (node.path("@type").asText().equals("korap:group")) {
Iterator<JsonNode> operands = node.path("operands").elements();
while (operands.hasNext())
@@ -39,7 +42,8 @@
addId(node);
}
- private JsonNode addId(JsonNode node) {
+
+ private JsonNode addId (JsonNode node) {
if (node.isObject()) {
ObjectNode o = (ObjectNode) node;
String s = extractToken(node);
@@ -49,7 +53,8 @@
return node;
}
- private String extractToken(JsonNode token) {
+
+ private String extractToken (JsonNode token) {
if (!token.path("@type").equals("korap:term")) {
JsonNode wrap = token.path("wrap");
JsonNode op = token.path("operands");
@@ -65,11 +70,14 @@
}
- @Deprecated public JsonNode getFinalNode() {
+
+ @Deprecated
+ public JsonNode getFinalNode () {
return this.node;
}
- public String toJSON() {
+
+ public String toJSON () {
try {
return mapper.writeValueAsString(node);
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQueryBuilder.java b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQueryBuilder.java
index 85b7a0e..eaca680 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQueryBuilder.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/MetaQueryBuilder.java
@@ -16,39 +16,43 @@
private Map meta;
private SpanContext spanContext;
+
public MetaQueryBuilder () {
this.meta = new LinkedHashMap();
}
+
/**
* context segment if context is either of type char or token.
* size can differ for left and right span
- *
+ *
* @param left
* @param leftType
* @param right
* @param rightType
* @return
*/
- public MetaQueryBuilder setSpanContext(Integer left, String leftType,
+ public MetaQueryBuilder setSpanContext (Integer left, String leftType,
Integer right, String rightType) {
this.spanContext = new SpanContext(left, leftType, right, rightType);
return this;
}
- public SpanContext getSpanContext() {
+
+ public SpanContext getSpanContext () {
return this.spanContext;
}
+
/**
* context if of type paragraph or sentence where left and right
* size delimiters are irrelevant; or 2-token, 2-char p/paragraph,
* s/sentence or token, char
- *
+ *
* @param context
* @return
*/
- public MetaQueryBuilder setSpanContext(String context) {
+ public MetaQueryBuilder setSpanContext (String context) {
if (context.startsWith("s") | context.startsWith("p"))
this.spanContext = new SpanContext(context);
else {
@@ -61,7 +65,8 @@
return this;
}
- public MetaQueryBuilder fillMeta(Integer pageIndex, Integer pageInteger,
+
+ public MetaQueryBuilder fillMeta (Integer pageIndex, Integer pageInteger,
Integer pageLength, String ctx, Boolean cutoff) {
if (pageIndex != null)
this.addEntry("startIndex", pageIndex);
@@ -76,12 +81,14 @@
return this;
}
- public MetaQueryBuilder addEntry(String name, Object value) {
+
+ public MetaQueryBuilder addEntry (String name, Object value) {
meta.put(name, value);
return this;
}
- public Map raw() {
+
+ public Map raw () {
if (this.spanContext != null)
meta.putAll(this.spanContext.raw());
return meta;
@@ -95,10 +102,11 @@
private int right_size;
private String context = null;
+
/**
* context segment if context is either of type char or token.
* size can differ for left and right span
- *
+ *
* @param ls
* @param lt
* @param rs
@@ -112,11 +120,13 @@
this.right_size = rs;
}
+
public SpanContext (String context) {
this.context = context;
}
- public Map raw() {
+
+ public Map raw () {
Map meta = new LinkedHashMap();
if (this.context == null) {
Map map = new LinkedHashMap();
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
index b188301..c3bd53f 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessor.java
@@ -15,7 +15,8 @@
import java.util.*;
/**
- * Map representation of PoliqarpPlus syntax tree as returned by ANTLR.
+ * Map representation of PoliqarpPlus syntax tree as returned by
+ * ANTLR.
* Most centrally, this class maintains a set of nested maps and
* lists which represent the JSON tree, which is built by the JSON
* serialiser on basis of the {@link #requestMap} at the root of
@@ -24,8 +25,9 @@
* keep track of which objects to embed in which containing
* objects.
*
- * This class expects the Poliqarp+ ANTLR grammar shipped with Koral v0.3.0.
- *
+ * This class expects the Poliqarp+ ANTLR grammar shipped with Koral
+ * v0.3.0.
+ *
* @author Joachim Bingel (bingel@ids-mannheim.de)
* @version 0.3.0
* @since 0.1.0
@@ -37,9 +39,11 @@
private int classCounter = 1;
LinkedHashMap<ParseTree, Integer> classWrapRegistry = new LinkedHashMap<ParseTree, Integer>();
-
+
+
/**
* Constructor
+ *
* @param query
* The syntax tree as returned by ANTLR
* @throws QueryException
@@ -50,8 +54,9 @@
log.info(">>> " + requestMap.get("query") + " <<<");
}
+
@Override
- public void process(String query) {
+ public void process (String query) {
ParseTree tree;
tree = parsePoliqarpQuery(query);
super.parser = this.parser;
@@ -66,6 +71,7 @@
}
}
+
/**
* Recursively calls itself with the children of the currently
* active node, traversing the tree nodes in a top-down,
@@ -76,13 +82,13 @@
* This method is effectively a list of if-statements that are
* responsible for treating the different node types correctly and
* filling the respective maps/lists.
- *
+ *
* @param node
* The currently processed node. The process(String
* query) method calls this method with the root.
* @throws QueryException
*/
- private void processNode(ParseTree node) {
+ private void processNode (ParseTree node) {
// Top-down processing
if (visited.contains(node))
return;
@@ -103,13 +109,13 @@
// in a class, e.g. by an alignment operation
if (classWrapRegistry.containsKey(node)) {
Integer classId = classWrapRegistry.get(node);
- LinkedHashMap<String, Object> spanClass =
- KoralObjectGenerator.makeSpanClass(classId);
+ LinkedHashMap<String, Object> spanClass = KoralObjectGenerator
+ .makeSpanClass(classId);
putIntoSuperObject(spanClass);
objectStack.push(spanClass);
stackedObjects++;
}
-
+
/*
****************************************************************
****************************************************************
@@ -200,11 +206,13 @@
openNodeCats.pop();
}
+
/**
* Processes a 'segment' node.
+ *
* @param node
*/
- private void processSegment(ParseTree node) {
+ private void processSegment (ParseTree node) {
// Cover possible quantification (i.e. repetition) of segment
ParseTree quantification = getFirstChildWithCat(node, "repetition");
if (quantification != null) {
@@ -219,11 +227,13 @@
}
}
+
/**
* Process a 'sequence' node.
+ *
* @param node
*/
- private void processSequence(ParseTree node) {
+ private void processSequence (ParseTree node) {
// skip in case of emptyTokenSequence or emptyTokenSequenceClass
if (node.getChildCount() == 1
&& getNodeCat(node.getChild(0))
@@ -233,8 +243,7 @@
// skip in case this sequence is just a container for an alignment
// node with just one child
if (node.getChildCount() == 1
- && getNodeCat(node.getChild(0))
- .equals("alignment")) {
+ && getNodeCat(node.getChild(0)).equals("alignment")) {
ParseTree alignmentNode = node.getChild(0);
if (alignmentNode.getChildCount() == 2) { // one child is the
// alignment operator (^), the other a segment
@@ -261,12 +270,13 @@
stackedObjects++;
}
+
@SuppressWarnings("unchecked")
/**
* empty tokens at beginning/end of sequence
* @param node
*/
- private void processEmptyTokenSequence(ParseTree node) {
+ private void processEmptyTokenSequence (ParseTree node) {
Integer[] minmax = parseEmptySegments(node);
// object will be either a repetition group or a single empty
// token
@@ -285,7 +295,8 @@
stackedObjects++;
}
- private void processEmptyTokenSequenceClass(ParseTree node) {
+
+ private void processEmptyTokenSequenceClass (ParseTree node) {
int classId = 1;
if (hasChild(node, "spanclass_id")) {
classId = Integer.parseInt(node.getChild(1).getChild(0)
@@ -299,7 +310,8 @@
stackedObjects++;
}
- private void processToken(ParseTree node) {
+
+ private void processToken (ParseTree node) {
LinkedHashMap<String, Object> token = KoralObjectGenerator.makeToken();
// handle negation
List<ParseTree> negations = getChildrenWithCat(node, "!");
@@ -356,40 +368,48 @@
visited.addAll(getChildren(node));
}
+
/**
- * Processes an 'alignment' node. These nodes represent alignment anchors
- * which introduce an alignment ruler in KWIC display. The serialization
- * for this expects the two segments to the left and to the right of each
- * anchor to be wrapped in classes, then these classes are referenced in
+ * Processes an 'alignment' node. These nodes represent alignment
+ * anchors
+ * which introduce an alignment ruler in KWIC display. The
+ * serialization
+ * for this expects the two segments to the left and to the right
+ * of each
+ * anchor to be wrapped in classes, then these classes are
+ * referenced in
* the <tt>alignment</tt> array of the request tree.
+ *
* @param node
*/
- private void processAlignment(ParseTree node) {
- int i=1;
+ private void processAlignment (ParseTree node) {
+ int i = 1;
if (node.getChild(0).getText().equals("^")) {
i = 0; // if there is no first child (anchor is at extreme left or
// right of segment), start counting at 0 in the loop
}
// for every alignment anchor, get its left and right child and register
// these to be wrapped in classes.
- for (; i<node.getChildCount(); i+=2) {
+ for (; i < node.getChildCount(); i += 2) {
int alignmentFirstArg = -1;
int alignmentSecondArg = -1;
- ParseTree leftChild = node.getChild(i-1);
- ParseTree rightChild = node.getChild(i+1);
+ ParseTree leftChild = node.getChild(i - 1);
+ ParseTree rightChild = node.getChild(i + 1);
if (leftChild != null) {
- if (! classWrapRegistry.containsKey(leftChild)) {
+ if (!classWrapRegistry.containsKey(leftChild)) {
alignmentFirstArg = classCounter++;
classWrapRegistry.put(leftChild, alignmentFirstArg);
- } else {
+ }
+ else {
alignmentFirstArg = classWrapRegistry.get(leftChild);
}
}
if (rightChild != null) {
- if (! classWrapRegistry.containsKey(rightChild)) {
+ if (!classWrapRegistry.containsKey(rightChild)) {
alignmentSecondArg = classCounter++;
classWrapRegistry.put(rightChild, alignmentSecondArg);
- } else {
+ }
+ else {
alignmentSecondArg = classWrapRegistry.get(rightChild);
}
}
@@ -397,14 +417,15 @@
}
}
- private void processSpan(ParseTree node) {
+
+ private void processSpan (ParseTree node) {
List<ParseTree> negations = getChildrenWithCat(node, "!");
boolean negated = false;
if (negations.size() % 2 == 1)
negated = true;
LinkedHashMap<String, Object> span = KoralObjectGenerator.makeSpan();
- LinkedHashMap<String, Object> wrappedTerm =
- KoralObjectGenerator.makeTerm();
+ LinkedHashMap<String, Object> wrappedTerm = KoralObjectGenerator
+ .makeTerm();
span.put("wrap", wrappedTerm);
ParseTree keyNode = getFirstChildWithCat(node, "key");
ParseTree layerNode = getFirstChildWithCat(node, "layer");
@@ -436,13 +457,13 @@
wrappedTerm.put("match", "match:ne");
}
if (termNode != null) {
- LinkedHashMap<String, Object> termOrTermGroup =
- parseTermOrTermGroup(termNode, negated, "span");
+ LinkedHashMap<String, Object> termOrTermGroup = parseTermOrTermGroup(
+ termNode, negated, "span");
span.put("attr", termOrTermGroup);
}
if (termGroupNode != null) {
- LinkedHashMap<String, Object> termOrTermGroup =
- parseTermOrTermGroup(termGroupNode, negated, "span");
+ LinkedHashMap<String, Object> termOrTermGroup = parseTermOrTermGroup(
+ termGroupNode, negated, "span");
span.put("attr", termOrTermGroup);
}
putIntoSuperObject(span);
@@ -450,24 +471,27 @@
stackedObjects++;
}
- private void processDisjunction(ParseTree node) {
- LinkedHashMap<String, Object> disjunction =
- KoralObjectGenerator.makeGroup("disjunction");
+
+ private void processDisjunction (ParseTree node) {
+ LinkedHashMap<String, Object> disjunction = KoralObjectGenerator
+ .makeGroup("disjunction");
putIntoSuperObject(disjunction);
objectStack.push(disjunction);
stackedObjects++;
}
- private void processPosition(ParseTree node) {
+
+ private void processPosition (ParseTree node) {
LinkedHashMap<String, Object> position = parseFrame(node.getChild(0));
putIntoSuperObject(position);
objectStack.push(position);
stackedObjects++;
}
- private void processRelation(ParseTree node) {
- LinkedHashMap<String, Object> relationGroup =
- KoralObjectGenerator.makeGroup("relation");
+
+ private void processRelation (ParseTree node) {
+ LinkedHashMap<String, Object> relationGroup = KoralObjectGenerator
+ .makeGroup("relation");
LinkedHashMap<String, Object> relation = KoralObjectGenerator
.makeRelation();
LinkedHashMap<String, Object> term = KoralObjectGenerator.makeTerm();
@@ -502,7 +526,8 @@
stackedObjects++;
}
- private void processSpanclass(ParseTree node) {
+
+ private void processSpanclass (ParseTree node) {
// Step I: get info
int classId = 1;
if (getNodeCat(node.getChild(1)).equals("spanclass_id")) {
@@ -518,8 +543,8 @@
addError(StatusCodes.INVALID_CLASS_REFERENCE, msg);
}
}
- LinkedHashMap<String, Object> classGroup =
- KoralObjectGenerator.makeSpanClass(classId);
+ LinkedHashMap<String, Object> classGroup = KoralObjectGenerator
+ .makeSpanClass(classId);
addHighlightClass(classId);
putIntoSuperObject(classGroup);
objectStack.push(classGroup);
@@ -527,7 +552,8 @@
}
- private void processMatching(ParseTree node) {
+
+ private void processMatching (ParseTree node) {
// Step I: get info
ArrayList<Integer> classRefs = new ArrayList<Integer>();
String classRefOp = null;
@@ -554,8 +580,8 @@
else {
classRefs.add(1); // default
}
- LinkedHashMap<String, Object> referenceGroup =
- KoralObjectGenerator.makeReference(classRefs);
+ LinkedHashMap<String, Object> referenceGroup = KoralObjectGenerator
+ .makeReference(classRefs);
String type = node.getChild(0).toStringTree(parser);
// Default is focus(), if deviating catch here
@@ -573,9 +599,10 @@
visited.add(node.getChild(0));
}
- private void processSubmatch(ParseTree node) {
- LinkedHashMap<String, Object> submatch =
- KoralObjectGenerator.makeReference(null);
+
+ private void processSubmatch (ParseTree node) {
+ LinkedHashMap<String, Object> submatch = KoralObjectGenerator
+ .makeReference(null);
submatch.put("operands", new ArrayList<Object>());
ParseTree startpos = getFirstChildWithCat(node, "startpos");
ParseTree length = getFirstChildWithCat(node, "length");
@@ -591,35 +618,37 @@
visited.add(node.getChild(0));
}
+
/**
* Creates meta field in requestMap, later filled by terms
*
* @param node
*/
- private void processMeta(ParseTree node) {
+ private void processMeta (ParseTree node) {
addWarning("You used the 'meta' keyword in a PoliqarpPlus query. This"
+ " feature is currently not supported. Please use virtual "
+ "collections to restrict documents by metadata.");
- CollectionQueryProcessor cq =
- new CollectionQueryProcessor(node.getChild(1).getText());
+ CollectionQueryProcessor cq = new CollectionQueryProcessor(node
+ .getChild(1).getText());
requestMap.put("collection", cq.getRequestMap().get("collection"));
for (ParseTree child : getChildren(node)) {
visited.add(child);
}
}
+
@SuppressWarnings("unchecked")
- private void processWithin(ParseTree node) {
+ private void processWithin (ParseTree node) {
ParseTree domainNode = node.getChild(1);
String domain = getNodeCat(domainNode);
LinkedHashMap<String, Object> span = KoralObjectGenerator
.makeSpan(domain);
- LinkedHashMap<String, Object> queryObj =
- (LinkedHashMap<String, Object>) requestMap.get("query");
+ LinkedHashMap<String, Object> queryObj = (LinkedHashMap<String, Object>) requestMap
+ .get("query");
LinkedHashMap<String, Object> contains = KoralObjectGenerator
.makePosition(new String[] { "frames:isAround" });
- ArrayList<Object> operands =
- (ArrayList<Object>) contains.get("operands");
+ ArrayList<Object> operands = (ArrayList<Object>) contains
+ .get("operands");
operands.add(span);
operands.add(queryObj);
requestMap.put("query", contains);
@@ -627,6 +656,7 @@
visited.add(node.getChild(1));
}
+
/**
* Parses a repetition node
*
@@ -636,7 +666,7 @@
* the quantified element, and the second element
* representing the maximal number of repetitions
*/
- private Integer[] parseRepetition(ParseTree node) {
+ private Integer[] parseRepetition (ParseTree node) {
Integer min = 0, max = 0;
boolean maxInfinite = false;
// (repetition) node can be of two types: 'kleene' or 'range'
@@ -685,7 +715,8 @@
return new Integer[] { min, max };
}
- private LinkedHashMap<String, Object> parseFrame(ParseTree node) {
+
+ private LinkedHashMap<String, Object> parseFrame (ParseTree node) {
String operator = node.toStringTree(parser).toLowerCase();
String[] frames = new String[] { "" };
switch (operator) {
@@ -696,10 +727,10 @@
frames = new String[] { "frames:matches" };
break;
case "startswith":
- frames = new String[] { "frames:startsWith","frames:matches" };
+ frames = new String[] { "frames:startsWith", "frames:matches" };
break;
case "endswith":
- frames = new String[] { "frames:endsWith","frames:matches" };
+ frames = new String[] { "frames:endsWith", "frames:matches" };
break;
case "overlaps":
frames = new String[] { "frames:overlapsLeft",
@@ -709,11 +740,13 @@
return KoralObjectGenerator.makePosition(frames);
}
- private LinkedHashMap<String, Object> parseTermOrTermGroup(ParseTree node,
+
+ private LinkedHashMap<String, Object> parseTermOrTermGroup (ParseTree node,
boolean negated) {
return parseTermOrTermGroup(node, negated, "token");
}
+
/**
* Parses a (term) or (termGroup) node
*
@@ -729,7 +762,7 @@
* @return A term or termGroup object, depending on input
*/
@SuppressWarnings("unchecked")
- private LinkedHashMap<String, Object> parseTermOrTermGroup(ParseTree node,
+ private LinkedHashMap<String, Object> parseTermOrTermGroup (ParseTree node,
boolean negatedGlobal, String mode) {
String nodeCat = getNodeCat(node);
if (nodeCat.equals("term")) {
@@ -848,6 +881,7 @@
return null;
}
+
/**
* Puts an object into the operands list of its governing (or
* "super") object which had been placed on the
@@ -858,10 +892,11 @@
* @param object
* The object to be inserted
*/
- private void putIntoSuperObject(LinkedHashMap<String, Object> object) {
+ private void putIntoSuperObject (LinkedHashMap<String, Object> object) {
putIntoSuperObject(object, 0);
}
+
/**
* Puts an object into the operands list of its governing (or
* "super") object which had been placed on the
@@ -877,7 +912,7 @@
* the stack is the super object.
*/
@SuppressWarnings({ "unchecked" })
- private void putIntoSuperObject(LinkedHashMap<String, Object> object,
+ private void putIntoSuperObject (LinkedHashMap<String, Object> object,
int objStackPosition) {
if (objectStack.size() > objStackPosition) {
ArrayList<Object> topObjectOperands = (ArrayList<Object>) objectStack
@@ -889,28 +924,33 @@
}
}
+
/**
- * Parses the min and max attributes for a boundary object as defined in
- * a distance node.
+ * Parses the min and max attributes for a boundary object as
+ * defined in
+ * a distance node.
*
- * @param distanceNode A node of category 'distance'
- * @return An array of two fields, where the first is the min value and the
- * second is the max value and may be null.
+ * @param distanceNode
+ * A node of category 'distance'
+ * @return An array of two fields, where the first is the min
+ * value and the
+ * second is the max value and may be null.
*/
- private Integer[] parseDistance(ParseTree distanceNode) {
- int emptyTokenSeqIndex =
- getNodeCat(distanceNode).equals("distance") ? 0 : 2;
+ private Integer[] parseDistance (ParseTree distanceNode) {
+ int emptyTokenSeqIndex = getNodeCat(distanceNode).equals("distance") ? 0
+ : 2;
Integer[] minmax = parseEmptySegments(distanceNode
.getChild(emptyTokenSeqIndex));
Integer min = minmax[0];
Integer max = minmax[1];
-// min++;
-// if (max != null)
-// max++;
+ // min++;
+ // if (max != null)
+ // max++;
return new Integer[] { min, max };
}
- private Integer[] parseEmptySegments(ParseTree emptySegments) {
+
+ private Integer[] parseEmptySegments (ParseTree emptySegments) {
Integer min = 0;
Integer max = 0;
ParseTree child;
@@ -940,11 +980,12 @@
return new Integer[] { min, max };
}
- private ParserRuleContext parsePoliqarpQuery(String query) {
+
+ private ParserRuleContext parsePoliqarpQuery (String query) {
Lexer lexer = new PoliqarpPlusLexer((CharStream) null);
ParserRuleContext tree = null;
- Antlr4DescriptiveErrorListener errorListener =
- new Antlr4DescriptiveErrorListener(query);
+ Antlr4DescriptiveErrorListener errorListener = new Antlr4DescriptiveErrorListener(
+ query);
// Like p. 111
try {
// Tokenize input data
@@ -962,8 +1003,8 @@
// Get starting rule from parser
Method startRule = PoliqarpPlusParser.class.getMethod("request");
- tree = (ParserRuleContext)
- startRule.invoke(parser, (Object[]) null);
+ tree = (ParserRuleContext) startRule
+ .invoke(parser, (Object[]) null);
}
// Some things went wrong ...
catch (Exception e) {
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
index eb6b61d..90d29ed 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/QuerySerializer.java
@@ -16,8 +16,10 @@
import java.util.*;
/**
- * Main class for Koral, serializes queries from concrete QLs to KoralQuery
- * @author Joachim Bingel (bingel@ids-mannheim.de),
+ * Main class for Koral, serializes queries from concrete QLs to
+ * KoralQuery
+ *
+ * @author Joachim Bingel (bingel@ids-mannheim.de),
* Michael Hanl (hanl@ids-mannheim.de)
* @version 0.3.0
* @since 0.1.0
@@ -28,8 +30,8 @@
static {
qlProcessorAssignment = new HashMap<String, Class<? extends AbstractQueryProcessor>>();
- qlProcessorAssignment
- .put("poliqarpplus", PoliqarpPlusQueryProcessor.class);
+ qlProcessorAssignment.put("poliqarpplus",
+ PoliqarpPlusQueryProcessor.class);
qlProcessorAssignment.put("cosmas2", Cosmas2QueryProcessor.class);
qlProcessorAssignment.put("annis", AnnisQueryProcessor.class);
qlProcessorAssignment.put("cql", CqlQueryProcessor.class);
@@ -48,10 +50,11 @@
private org.slf4j.Logger log = LoggerFactory
.getLogger(QuerySerializer.class);
+
/**
* @param args
*/
- public static void main(String[] args) {
+ public static void main (String[] args) {
/*
* just for testing...
*/
@@ -61,12 +64,13 @@
String[] queries = null;
String ql = "poliqarpplus";
if (args.length < 2) {
- System.err.println("Usage: QuerySerializer \"query\" queryLanguage");
+ System.err
+ .println("Usage: QuerySerializer \"query\" queryLanguage");
System.exit(1);
}
else {
queries = new String[] { args[0] };
- ql = args[1];
+ ql = args[1];
}
for (String q : queries) {
i++;
@@ -90,19 +94,23 @@
}
}
+
/**
* Runs the QuerySerializer by initializing the relevant
* AbstractSyntaxTree implementation (depending on specified query
* language) and transforms and writes the tree's requestMap to
* the specified output file.
- *
- * @param outFile The file to which the serialization is written
- * @param query The query string
- * @param queryLanguage The query language. As of 17 Dec 2014, this must be
- * one of 'poliqarpplus', 'cosmas2', 'annis' or 'cql'.
+ *
+ * @param outFile
+ * The file to which the serialization is written
+ * @param query
+ * The query string
+ * @param queryLanguage
+ * The query language. As of 17 Dec 2014, this must be
+ * one of 'poliqarpplus', 'cosmas2', 'annis' or 'cql'.
* @throws IOException
*/
- public void run(String query, String queryLanguage) throws IOException {
+ public void run (String query, String queryLanguage) throws IOException {
if (queryLanguage.equalsIgnoreCase("poliqarp")) {
ast = new PoliqarpPlusQueryProcessor(query);
}
@@ -119,13 +127,14 @@
ast = new AnnisQueryProcessor(query);
}
else {
- throw new IllegalArgumentException(
- queryLanguage + " is not a supported query language!");
+ throw new IllegalArgumentException(queryLanguage
+ + " is not a supported query language!");
}
toJSON();
}
- public QuerySerializer setQuery(String query, String ql, String version) {
+
+ public QuerySerializer setQuery (String query, String ql, String version) {
ast = new DummyQueryProcessor();
if (query == null || query.isEmpty()) {
ast.addError(StatusCodes.NO_QUERY, "You did not specify a query!");
@@ -153,21 +162,24 @@
ast = new AnnisQueryProcessor(query);
}
else {
- ast.addError(StatusCodes.UNKNOWN_QL,
- ql + " is not a supported query language!");
+ ast.addError(StatusCodes.UNKNOWN_QL, ql
+ + " is not a supported query language!");
}
return this;
}
- public QuerySerializer setQuery(String query, String ql) {
+
+ public QuerySerializer setQuery (String query, String ql) {
return setQuery(query, ql, "");
}
- public void setVerbose(boolean verbose) {
+
+ public void setVerbose (boolean verbose) {
AbstractQueryProcessor.verbose = verbose;
}
- public final String toJSON() {
+
+ public final String toJSON () {
String ser;
try {
ser = mapper.writeValueAsString(raw());
@@ -179,11 +191,13 @@
return ser;
}
- public final Map build() {
+
+ public final Map build () {
return raw();
}
- private Map raw() {
+
+ private Map raw () {
if (ast != null) {
Map<String, Object> requestMap = ast.getRequestMap();
Map meta = (Map) requestMap.get("meta");
@@ -215,8 +229,9 @@
return new HashMap<>();
}
- private Map<String, Object> mergeCollection(Map<String, Object> collection1,
- Map<String, Object> collection2) {
+
+ private Map<String, Object> mergeCollection (
+ Map<String, Object> collection1, Map<String, Object> collection2) {
LinkedHashMap<String, Object> docGroup = KoralObjectGenerator
.makeDocGroup("and");
ArrayList<Object> operands = (ArrayList<Object>) docGroup
@@ -234,7 +249,8 @@
}
}
- public QuerySerializer addMeta(String cli, String cri, int cls, int crs,
+
+ public QuerySerializer addMeta (String cli, String cri, int cls, int crs,
int num, int pageIndex) {
MetaQueryBuilder meta = new MetaQueryBuilder();
meta.setSpanContext(cls, cli, crs, cri);
@@ -244,7 +260,8 @@
return this;
}
- public QuerySerializer addMeta(String context, int num, int pageidx) {
+
+ public QuerySerializer addMeta (String context, int num, int pageidx) {
MetaQueryBuilder meta = new MetaQueryBuilder();
meta.addEntry("startIndex", pageidx);
meta.addEntry("count", num);
@@ -253,19 +270,21 @@
return this;
}
- public QuerySerializer addMeta(MetaQueryBuilder meta) {
+
+ public QuerySerializer addMeta (MetaQueryBuilder meta) {
this.meta = meta.raw();
return this;
}
-// @Deprecated public QuerySerializer setCollectionSimple(String collection) {
-// CollectionQueryBuilder qobj = new CollectionQueryBuilder();
-// qobj.addResource(collection);
-// this.collection = (Map<String, Object>) qobj.raw();
-// return this;
-// }
- public QuerySerializer setCollection(String collection) {
+ // @Deprecated public QuerySerializer setCollectionSimple(String collection) {
+ // CollectionQueryBuilder qobj = new CollectionQueryBuilder();
+ // qobj.addResource(collection);
+ // this.collection = (Map<String, Object>) qobj.raw();
+ // return this;
+ // }
+
+ public QuerySerializer setCollection (String collection) {
CollectionQueryProcessor tree = new CollectionQueryProcessor();
Map<String, Object> collectionRequest = tree.getRequestMap();
tree.process(collection);
@@ -277,7 +296,7 @@
return this;
}
-// public QuerySerializer setCollection(CollectionQueryBuilder2 collections) {
+ // public QuerySerializer setCollection(CollectionQueryBuilder2 collections) {
// this.collection = (Map<String, Object>) collections.raw();
// return this;
// }
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java b/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java
index ef06c93..7c3128a 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/QueryUtils.java
@@ -13,7 +13,7 @@
import java.util.regex.Pattern;
/**
- * @author Joachim Bingel (bingel@ids-mannheim.de),
+ * @author Joachim Bingel (bingel@ids-mannheim.de),
* Michael Hanl (hanl@ids-mannheim.de)
* @date 10/12/2013
* @version 0.3.0
@@ -21,7 +21,7 @@
*/
public class QueryUtils {
- public static SimpleEntry<String, Integer> checkUnbalancedPars(String q) {
+ public static SimpleEntry<String, Integer> checkUnbalancedPars (String q) {
Map<Character, Character> brackets = new HashMap<Character, Character>();
brackets.put('[', ']');
brackets.put('{', '}');
@@ -51,13 +51,15 @@
return null;
}
- public static List<String> parseMorph(String stringTree) {
+
+ public static List<String> parseMorph (String stringTree) {
ArrayList<String> morph = new ArrayList<String>();
return morph;
}
- public static String buildCypherQuery(String cypher, String ctypel,
+
+ public static String buildCypherQuery (String cypher, String ctypel,
String ctyper, int cl, int cr, int page, int limit) {
// todo: implies that there is only one type allowed!
String sctypel = "", sctyper = "";
@@ -108,7 +110,8 @@
return buffer.toString();
}
- public static String buildDotQuery(long sid, String graphdb_id) {
+
+ public static String buildDotQuery (long sid, String graphdb_id) {
StringBuffer b = new StringBuffer();
b.append("<query>");
b.append("<sentenceId>");
@@ -130,7 +133,8 @@
return b.toString();
}
- public String buildaggreQuery(String query) {
+
+ public String buildaggreQuery (String query) {
StringBuffer b = new StringBuffer();
b.append("<query><cypher><![CDATA[");
b.append(query);
@@ -159,9 +163,10 @@
return b.toString();
}
+
@Deprecated
- public static Map addParameters(Map request, int page, int num, String cli,
- String cri, int cls, int crs, boolean cutoff) {
+ public static Map addParameters (Map request, int page, int num,
+ String cli, String cri, int cls, int crs, boolean cutoff) {
Map ctx = new LinkedHashMap();
List left = new ArrayList();
left.add(cli);
@@ -180,7 +185,8 @@
return request;
}
- public static String escapeRegexSpecialChars(String key) {
+
+ public static String escapeRegexSpecialChars (String key) {
key.replace("\\", "\\\\");
Pattern p = Pattern
.compile("\\.|\\^|\\$|\\||\\?|\\*|\\+|\\(|\\)|\\[|\\]|\\{|\\}");
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/TreeTemplate.java b/src/main/java/de/ids_mannheim/korap/query/serialize/TreeTemplate.java
index 2e9d074..b6ce44b 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/TreeTemplate.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/TreeTemplate.java
@@ -31,6 +31,7 @@
public class TreeTemplate extends Antlr4AbstractQueryProcessor {
private static Logger log = LoggerFactory.getLogger(TreeTemplate.class);
+
/**
*
* @param tree
@@ -44,8 +45,9 @@
process(query);
}
+
@Override
- public void process(String query) {
+ public void process (String query) {
ParseTree tree = parseQuery(query);
super.parser = this.parser;
if (tree != null) {
@@ -58,7 +60,8 @@
}
}
- private void processNode(ParseTree node) {
+
+ private void processNode (ParseTree node) {
// Top-down processing
if (visited.contains(node))
return;
@@ -74,7 +77,7 @@
System.err.println(" " + objectStack);
System.out.println(openNodeCats);
}
-
+
/*
****************************************************************
****************************************************************
@@ -111,13 +114,15 @@
}
+
@SuppressWarnings("unused")
- private void putIntoSuperObject(LinkedHashMap<String, Object> object) {
+ private void putIntoSuperObject (LinkedHashMap<String, Object> object) {
putIntoSuperObject(object, 0);
}
+
@SuppressWarnings({ "unchecked" })
- private void putIntoSuperObject(LinkedHashMap<String, Object> object,
+ private void putIntoSuperObject (LinkedHashMap<String, Object> object,
int objStackPosition) {
if (objectStack.size() > objStackPosition) {
ArrayList<Object> topObjectOperands = (ArrayList<Object>) objectStack
@@ -130,7 +135,8 @@
}
}
- private ParserRuleContext parseQuery(String q) {
+
+ private ParserRuleContext parseQuery (String q) {
// TODO replace AqlLexer with lexer for your Antlr4 grammar!
Lexer qlLexer = new AqlLexer((CharStream) null);
ParserRuleContext tree = null;
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/util/Antlr3DescriptiveErrorListener.java b/src/main/java/de/ids_mannheim/korap/query/serialize/util/Antlr3DescriptiveErrorListener.java
index cf81273..6e574fd 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/util/Antlr3DescriptiveErrorListener.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/util/Antlr3DescriptiveErrorListener.java
@@ -14,7 +14,7 @@
* (generated source directory).
*
* @author Joachim Bingel (bingel@ids-mannheim.de)
- *
+ *
*/
public class Antlr3DescriptiveErrorListener implements IErrorReporter {
@@ -23,12 +23,14 @@
private String expected;
private int charPosition;
+
public Antlr3DescriptiveErrorListener (String query) {
this.query = query;
};
+
@Override
- public void reportError(String error) {
+ public void reportError (String error) {
String charPositionStr = null;
String offendingSymbol = null;
String expected = null;
@@ -48,7 +50,8 @@
this.expected = expected;
}
- public ArrayList<Object> generateFullErrorMsg() {
+
+ public ArrayList<Object> generateFullErrorMsg () {
ArrayList<Object> errorSpecs = new ArrayList<Object>();
String msg = getDetailedErrorMessage();
errorSpecs.add(StatusCodes.MALFORMED_QUERY);
@@ -57,7 +60,8 @@
return errorSpecs;
}
- private String getDetailedErrorMessage() {
+
+ private String getDetailedErrorMessage () {
// default message, in case no detailed info is available;
String msg = "Malformed query. Could not parse.";
char offendingSymbol = query.charAt(0);
@@ -87,7 +91,8 @@
return msg;
}
- public int getCharPosition() {
+
+ public int getCharPosition () {
return charPosition;
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/util/Antlr4DescriptiveErrorListener.java b/src/main/java/de/ids_mannheim/korap/query/serialize/util/Antlr4DescriptiveErrorListener.java
index 7fa82aa..37cd731 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/util/Antlr4DescriptiveErrorListener.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/util/Antlr4DescriptiveErrorListener.java
@@ -16,12 +16,14 @@
int line;
int charPosition;
+
public Antlr4DescriptiveErrorListener (String query) {
this.query = query;
};
+
@Override
- public void syntaxError(Recognizer<?, ?> recognizer,
+ public void syntaxError (Recognizer<?, ?> recognizer,
Object offendingSymbol, int line, int charPositionInLine,
String msg, RecognitionException e) {
this.message = msg;
@@ -29,19 +31,23 @@
this.charPosition = charPositionInLine;
}
- public String getMessage() {
+
+ public String getMessage () {
return message;
}
- public int getLine() {
+
+ public int getLine () {
return line;
}
- public int getCharPosition() {
+
+ public int getCharPosition () {
return charPosition;
}
- public ArrayList<Object> generateFullErrorMsg() {
+
+ public ArrayList<Object> generateFullErrorMsg () {
ArrayList<Object> errorSpecs = new ArrayList<Object>();
String msg = getDetailedErrorMessage();
errorSpecs.add(StatusCodes.MALFORMED_QUERY);
@@ -50,7 +56,8 @@
return errorSpecs;
}
- private String getDetailedErrorMessage() {
+
+ private String getDetailedErrorMessage () {
// default message, in case no detailed info is available;
String msg = "Malformed query. Could not parse.";
char offendingSymbol = query.charAt(0);
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/util/CosmasCondition.java b/src/main/java/de/ids_mannheim/korap/query/serialize/util/CosmasCondition.java
index 4c79500..7da31b4 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/util/CosmasCondition.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/util/CosmasCondition.java
@@ -4,23 +4,25 @@
public class CosmasCondition {
- public boolean negated = false;
- public String elem = "";
- public String position = "";
-
- public CosmasCondition(Tree cond) {
- String nodeString = cond.toStringTree();
- if (nodeString.startsWith("-")) {
- negated = true;
- nodeString = nodeString.substring(1);
- } else if (nodeString.startsWith("+")) {
- nodeString = nodeString.substring(1);
- }
-
- elem = nodeString.substring(0, 1);
- nodeString = nodeString.substring(1);
-
- position = nodeString.equals("a") ?
- "frames:startswith" : "frames:endswith";
- }
+ public boolean negated = false;
+ public String elem = "";
+ public String position = "";
+
+
+ public CosmasCondition (Tree cond) {
+ String nodeString = cond.toStringTree();
+ if (nodeString.startsWith("-")) {
+ negated = true;
+ nodeString = nodeString.substring(1);
+ }
+ else if (nodeString.startsWith("+")) {
+ nodeString = nodeString.substring(1);
+ }
+
+ elem = nodeString.substring(0, 1);
+ nodeString = nodeString.substring(1);
+
+ position = nodeString.equals("a") ? "frames:startswith"
+ : "frames:endswith";
+ }
}
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralObjectGenerator.java b/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralObjectGenerator.java
index 34a4266..20de50c 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralObjectGenerator.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/util/KoralObjectGenerator.java
@@ -11,30 +11,35 @@
protected static final Integer MAXIMUM_DISTANCE = 100;
private static AbstractQueryProcessor qp;
- public static void setQueryProcessor(AbstractQueryProcessor qp) {
+
+ public static void setQueryProcessor (AbstractQueryProcessor qp) {
KoralObjectGenerator.qp = qp;
}
- public static LinkedHashMap<String, Object> makeSpan() {
+
+ public static LinkedHashMap<String, Object> makeSpan () {
LinkedHashMap<String, Object> span = new LinkedHashMap<String, Object>();
span.put("@type", "koral:span");
return span;
}
- public static LinkedHashMap<String, Object> makeSpan(String key) {
+
+ public static LinkedHashMap<String, Object> makeSpan (String key) {
LinkedHashMap<String, Object> span = new LinkedHashMap<String, Object>();
span.put("@type", "koral:span");
span.put("key", key);
return span;
}
- public static LinkedHashMap<String, Object> makeTerm() {
+
+ public static LinkedHashMap<String, Object> makeTerm () {
LinkedHashMap<String, Object> term = new LinkedHashMap<String, Object>();
term.put("@type", "koral:term");
return term;
}
- public static LinkedHashMap<String, Object> makeTermGroup(String relation) {
+
+ public static LinkedHashMap<String, Object> makeTermGroup (String relation) {
LinkedHashMap<String, Object> term = new LinkedHashMap<String, Object>();
term.put("@type", "koral:termGroup");
term.put("relation", "relation:" + relation);
@@ -42,13 +47,15 @@
return term;
}
- public static LinkedHashMap<String, Object> makeDoc() {
+
+ public static LinkedHashMap<String, Object> makeDoc () {
LinkedHashMap<String, Object> term = new LinkedHashMap<String, Object>();
term.put("@type", "koral:doc");
return term;
}
- public static LinkedHashMap<String, Object> makeDocGroup(String relation) {
+
+ public static LinkedHashMap<String, Object> makeDocGroup (String relation) {
LinkedHashMap<String, Object> term = new LinkedHashMap<String, Object>();
term.put("@type", "koral:docGroup");
term.put("operation", "operation:" + relation);
@@ -56,13 +63,15 @@
return term;
}
- public static LinkedHashMap<String, Object> makeToken() {
+
+ public static LinkedHashMap<String, Object> makeToken () {
LinkedHashMap<String, Object> token = new LinkedHashMap<String, Object>();
token.put("@type", "koral:token");
return token;
}
- public static LinkedHashMap<String, Object> makeGroup(String operation) {
+
+ public static LinkedHashMap<String, Object> makeGroup (String operation) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
group.put("@type", "koral:group");
group.put("operation", "operation:" + operation);
@@ -70,7 +79,8 @@
return group;
}
- public static LinkedHashMap<String, Object> makeRepetition(Integer min,
+
+ public static LinkedHashMap<String, Object> makeRepetition (Integer min,
Integer max) {
LinkedHashMap<String, Object> group = makeGroup("repetition");
group.put("boundary", makeBoundary(min, max));
@@ -78,8 +88,9 @@
return group;
}
+
@Deprecated
- public static LinkedHashMap<String, Object> makePosition(String frame) {
+ public static LinkedHashMap<String, Object> makePosition (String frame) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
group.put("@type", "koral:group");
group.put("operation", "operation:position");
@@ -88,7 +99,8 @@
return group;
}
- public static LinkedHashMap<String, Object> makePosition(
+
+ public static LinkedHashMap<String, Object> makePosition (
String[] allowedFrames) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
group.put("@type", "koral:group");
@@ -98,12 +110,14 @@
return group;
}
- public static LinkedHashMap<String, Object> makeSpanClass(int classId) {
+
+ public static LinkedHashMap<String, Object> makeSpanClass (int classId) {
return makeSpanClass(classId, false);
}
+
@Deprecated
- public static LinkedHashMap<String, Object> makeSpanClass(int classId,
+ public static LinkedHashMap<String, Object> makeSpanClass (int classId,
boolean setBySystem) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
group.put("@type", "koral:group");
@@ -119,7 +133,8 @@
return group;
}
- public static LinkedHashMap<String, Object> makeClassRefCheck(
+
+ public static LinkedHashMap<String, Object> makeClassRefCheck (
ArrayList<String> check, Integer[] classIn, int classOut) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
group.put("@type", "koral:group");
@@ -131,7 +146,8 @@
return group;
}
- public static LinkedHashMap<String, Object> makeClassRefOp(
+
+ public static LinkedHashMap<String, Object> makeClassRefOp (
String operation, Integer[] classIn, int classOut) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
group.put("@type", "koral:group");
@@ -143,8 +159,9 @@
return group;
}
+
@Deprecated
- public static LinkedHashMap<String, Object> makeTreeRelation(String reltype) {
+ public static LinkedHashMap<String, Object> makeTreeRelation (String reltype) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
group.put("@type", "koral:treeRelation");
if (reltype != null)
@@ -152,13 +169,15 @@
return group;
}
- public static LinkedHashMap<String, Object> makeRelation() {
+
+ public static LinkedHashMap<String, Object> makeRelation () {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
group.put("@type", "koral:relation");
return group;
}
- public static LinkedHashMap<String, Object> makeBoundary(Integer min,
+
+ public static LinkedHashMap<String, Object> makeBoundary (Integer min,
Integer max) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
group.put("@type", "koral:boundary");
@@ -169,7 +188,8 @@
return group;
}
- public static LinkedHashMap<String, Object> makeDistance(String key,
+
+ public static LinkedHashMap<String, Object> makeDistance (String key,
Integer min, Integer max) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
if (key.equals("w")) {
@@ -190,7 +210,8 @@
return group;
}
- public static LinkedHashMap<String, Object> makeReference(
+
+ public static LinkedHashMap<String, Object> makeReference (
ArrayList<Integer> classRefs, String operation) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
group.put("@type", "koral:reference");
@@ -201,13 +222,15 @@
return group;
}
- public static LinkedHashMap<String, Object> makeReference(
+
+ public static LinkedHashMap<String, Object> makeReference (
ArrayList<Integer> classRefs) {
return makeReference(classRefs, "focus");
}
+
@Deprecated
- public static LinkedHashMap<String, Object> makeReference(int classRef,
+ public static LinkedHashMap<String, Object> makeReference (int classRef,
String operation, boolean setBySystem) {
ArrayList<Integer> classRefs = new ArrayList<Integer>();
if (setBySystem)
@@ -216,8 +239,9 @@
return makeReference(classRefs, operation);
}
+
@Deprecated
- public static LinkedHashMap<String, Object> makeReference(int classRef,
+ public static LinkedHashMap<String, Object> makeReference (int classRef,
boolean setBySystem) {
ArrayList<Integer> classRefs = new ArrayList<Integer>();
if (setBySystem)
@@ -226,12 +250,14 @@
return makeReference(classRefs, "focus");
}
- public static LinkedHashMap<String, Object> makeReference(int classRef) {
+
+ public static LinkedHashMap<String, Object> makeReference (int classRef) {
return makeReference(classRef, false);
}
+
@Deprecated
- public static LinkedHashMap<String, Object> makeResetReference() {
+ public static LinkedHashMap<String, Object> makeResetReference () {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
group.put("@type", "koral:reference");
group.put("operation", "operation:focus");
@@ -240,7 +266,8 @@
return group;
}
- public static LinkedHashMap<String, Object> makeSpanReference(
+
+ public static LinkedHashMap<String, Object> makeSpanReference (
Integer[] spanRef, String operation) {
LinkedHashMap<String, Object> group = new LinkedHashMap<String, Object>();
group.put("@type", "koral:reference");
@@ -250,12 +277,14 @@
return group;
}
- public static void addOperandsToGroup(LinkedHashMap<String, Object> group) {
+
+ public static void addOperandsToGroup (LinkedHashMap<String, Object> group) {
ArrayList<Object> operands = new ArrayList<Object>();
group.put("operands", operands);
}
-
- public static LinkedHashMap<String, Object> wrapInReference(
+
+
+ public static LinkedHashMap<String, Object> wrapInReference (
LinkedHashMap<String, Object> group, Integer classId) {
LinkedHashMap<String, Object> refGroup = makeReference(classId);
ArrayList<Object> operands = new ArrayList<Object>();
@@ -263,10 +292,11 @@
refGroup.put("operands", operands);
return refGroup;
}
-
+
+
@Deprecated
- public static LinkedHashMap<String, Object> wrapInReference(
- LinkedHashMap<String, Object> group, Integer classId,
+ public static LinkedHashMap<String, Object> wrapInReference (
+ LinkedHashMap<String, Object> group, Integer classId,
boolean setBySystem) {
LinkedHashMap<String, Object> refGroup = makeReference(classId);
ArrayList<Object> operands = new ArrayList<Object>();
@@ -275,14 +305,16 @@
return refGroup;
}
+
@SuppressWarnings("unchecked")
- public static LinkedHashMap<String, Object> wrapInClass(
+ public static LinkedHashMap<String, Object> wrapInClass (
LinkedHashMap<String, Object> group, Integer classId) {
LinkedHashMap<String, Object> classGroup = makeSpanClass(classId);
((ArrayList<Object>) classGroup.get("operands")).add(group);
return classGroup;
}
+
/**
* Ensures that a distance or quantification value does not exceed
* the allowed maximum value.
@@ -291,7 +323,7 @@
* @return The input number if it is below the allowed maximum
* value, else the maximum value.
*/
- public static int cropToMaxValue(int number) {
+ public static int cropToMaxValue (int number) {
if (number > MAXIMUM_DISTANCE) {
number = MAXIMUM_DISTANCE;
String warning = String
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/util/ResourceMapper.java b/src/main/java/de/ids_mannheim/korap/query/serialize/util/ResourceMapper.java
index 661976d..87f768a 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/util/ResourceMapper.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/util/ResourceMapper.java
@@ -21,7 +21,8 @@
map.put("ANA", "p");
}
- public static String descriptor2policy(String descriptor) {
+
+ public static String descriptor2policy (String descriptor) {
if (map.containsKey(descriptor))
return map.get(descriptor);
else
diff --git a/src/main/java/de/ids_mannheim/korap/query/serialize/util/StatusCodes.java b/src/main/java/de/ids_mannheim/korap/query/serialize/util/StatusCodes.java
index 993ba38..10614ea 100644
--- a/src/main/java/de/ids_mannheim/korap/query/serialize/util/StatusCodes.java
+++ b/src/main/java/de/ids_mannheim/korap/query/serialize/util/StatusCodes.java
@@ -1,13 +1,13 @@
package de.ids_mannheim.korap.query.serialize.util;
public class StatusCodes {
- public final static int NO_QUERY = 301;
- public final static int MALFORMED_QUERY = 302;
- public final static int DEPRECATED_QUERY_ELEMENT = 303;
- public final static int INVALID_CLASS_REFERENCE = 304;
- public final static int INCOMPATIBLE_OPERATOR_AND_OPERAND = 305;
- public final static int UNKNOWN_QUERY_ELEMENT = 306;
- public final static int UNKNOWN_QL = 307;
- public final static int UNBOUND_ANNIS_RELATION = 308;
- public final static int UNKNOWN_QUERY_ERROR = 399;
+ public final static int NO_QUERY = 301;
+ public final static int MALFORMED_QUERY = 302;
+ public final static int DEPRECATED_QUERY_ELEMENT = 303;
+ public final static int INVALID_CLASS_REFERENCE = 304;
+ public final static int INCOMPATIBLE_OPERATOR_AND_OPERAND = 305;
+ public final static int UNKNOWN_QUERY_ELEMENT = 306;
+ public final static int UNKNOWN_QL = 307;
+ public final static int UNBOUND_ANNIS_RELATION = 308;
+ public final static int UNKNOWN_QUERY_ERROR = 399;
}
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessorTest.java
index fc1b74d..114fc2c 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/AnnisQueryProcessorTest.java
@@ -1,4 +1,5 @@
package de.ids_mannheim.korap.query.serialize;
+
import static org.junit.Assert.*;
import java.io.IOException;
@@ -14,7 +15,8 @@
import de.ids_mannheim.korap.query.serialize.util.StatusCodes;
/**
- * Tests for JSON-LD serialization of ANNIS QL queries.
+ * Tests for JSON-LD serialization of ANNIS QL queries.
+ *
* @author Joachim Bingel (bingel@ids-mannheim.de)
* @version 1.0
*/
@@ -27,8 +29,9 @@
ObjectMapper mapper = new ObjectMapper();
JsonNode res;
+
@Test
- public void testContext() throws JsonProcessingException, IOException {
+ public void testContext () throws JsonProcessingException, IOException {
String contextUrl = "http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld";
query = "foo";
qs.setQuery(query, "annis");
@@ -36,302 +39,379 @@
assertEquals(contextUrl, res.get("@context").asText());
}
+
@Test
- public void testSingleTokens() throws JsonProcessingException, IOException {
+ public void testSingleTokens () throws JsonProcessingException, IOException {
query = "\"Mann\"";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("orth", res.at("/query/wrap/layer").asText());
- assertEquals("Mann", res.at("/query/wrap/key").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("Mann", res.at("/query/wrap/key").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
query = "tok!=\"Frau\"";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("orth", res.at("/query/wrap/layer").asText());
- assertEquals("Frau", res.at("/query/wrap/key").asText());
- assertEquals("match:ne", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("Frau", res.at("/query/wrap/key").asText());
+ assertEquals("match:ne", res.at("/query/wrap/match").asText());
query = "tok"; // special keyword for token
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
query = "Mann"; // no special keyword -> defaults to layer name
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("Mann", res.at("/query/layer").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("Mann", res.at("/query/layer").asText());
}
- @Test
- public void testSpans() throws JsonProcessingException, IOException {
+
+ @Test
+ public void testSpans () throws JsonProcessingException, IOException {
query = "node"; // special keyword for general span
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
query = "cat=\"np\""; // cat is special keyword for spans
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("np", res.at("/query/key").asText());
- assertEquals("c", res.at("/query/layer").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("np", res.at("/query/key").asText());
+ assertEquals("c", res.at("/query/layer").asText());
- query = "cat=\"NP\"";
+ query = "cat=\"NP\"";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("NP", res.at("/query/key").asText());
- assertEquals("c", res.at("/query/layer").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("NP", res.at("/query/key").asText());
+ assertEquals("c", res.at("/query/layer").asText());
}
- @Test
- public void testRegex() throws JsonProcessingException, IOException {
- query = "/Mann/";
- qs.setQuery(query, "annis");
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("type:regex", res.at("/query/wrap/type").asText());
- assertEquals("orth", res.at("/query/wrap/layer").asText());
- assertEquals("Mann", res.at("/query/wrap/key").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
- query = "/.*?Mann.*?/";
+ @Test
+ public void testRegex () throws JsonProcessingException, IOException {
+ query = "/Mann/";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("type:regex", res.at("/query/wrap/type").asText());
- assertEquals(".*?Mann.*?", res.at("/query/wrap/key").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("type:regex", res.at("/query/wrap/type").asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("Mann", res.at("/query/wrap/key").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
+
+ query = "/.*?Mann.*?/";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("type:regex", res.at("/query/wrap/type").asText());
+ assertEquals(".*?Mann.*?", res.at("/query/wrap/key").asText());
}
+
@Test
- public void testFoundriesLayers() throws JsonProcessingException, IOException {
- query = "c=\"np\"";
+ public void testFoundriesLayers () throws JsonProcessingException,
+ IOException {
+ query = "c=\"np\"";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("np", res.at("/query/key").asText());
- assertEquals("c", res.at("/query/layer").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("np", res.at("/query/key").asText());
+ assertEquals("c", res.at("/query/layer").asText());
- query = "cnx/c=\"np\"";
+ query = "cnx/c=\"np\"";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("np", res.at("/query/key").asText());
- assertEquals("c", res.at("/query/layer").asText());
- assertEquals("cnx", res.at("/query/foundry").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("np", res.at("/query/key").asText());
+ assertEquals("c", res.at("/query/layer").asText());
+ assertEquals("cnx", res.at("/query/foundry").asText());
- query = "tt/pos=\"np\"";
+ query = "tt/pos=\"np\"";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("np", res.at("/query/wrap/key").asText());
- assertEquals("p", res.at("/query/wrap/layer").asText());
- assertEquals("tt", res.at("/query/wrap/foundry").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("np", res.at("/query/wrap/key").asText());
+ assertEquals("p", res.at("/query/wrap/layer").asText());
+ assertEquals("tt", res.at("/query/wrap/foundry").asText());
}
+
@Test
- public void testDirectDeclarationRelations() throws JsonProcessingException, IOException {
- query = "node > node";
+ public void testDirectDeclarationRelations ()
+ throws JsonProcessingException, IOException {
+ query = "node > node";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:relation", res.at("/query/operation").asText());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
- assertEquals("koral:relation", res.at("/query/relation/@type").asText());
- assertEquals("koral:term", res.at("/query/relation/wrap/@type").asText());
- assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+ assertEquals("koral:term", res.at("/query/relation/wrap/@type")
+ .asText());
+ assertEquals("c", res.at("/query/relation/wrap/layer").asText());
- query = "node > cnx/c=\"np\"";
+ query = "node > cnx/c=\"np\"";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:relation", res.at("/query/operation").asText());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
- assertEquals("np", res.at("/query/operands/1/key").asText());
- assertEquals("c", res.at("/query/operands/1/layer").asText());
- assertEquals("cnx", res.at("/query/operands/1/foundry").asText());
- assertEquals("koral:relation", res.at("/query/relation/@type").asText());
- assertEquals("koral:term", res.at("/query/relation/wrap/@type").asText());
- assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("np", res.at("/query/operands/1/key").asText());
+ assertEquals("c", res.at("/query/operands/1/layer").asText());
+ assertEquals("cnx", res.at("/query/operands/1/foundry").asText());
+ assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+ assertEquals("koral:term", res.at("/query/relation/wrap/@type")
+ .asText());
+ assertEquals("c", res.at("/query/relation/wrap/layer").asText());
- query = "cnx/c=\"np\" > node";
+ query = "cnx/c=\"np\" > node";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals(true, res.at("/query/operands/1/key").isMissingNode());
- assertEquals("np", res.at("/query/operands/0/key").asText());
+ assertEquals(true, res.at("/query/operands/1/key").isMissingNode());
+ assertEquals("np", res.at("/query/operands/0/key").asText());
query = "cat=/NP/ & cat=/PP/ > #1";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:relation", res.at("/query/operation").asText());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("PP", res.at("/query/operands/0/key").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
- assertEquals("NP", res.at("/query/operands/1/key").asText());
- assertEquals(true, res.at("/query/operands/2").isMissingNode());
- assertEquals("koral:relation", res.at("/query/relation/@type").asText());
- assertEquals("koral:term", res.at("/query/relation/wrap/@type").asText());
- assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("PP", res.at("/query/operands/0/key").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("NP", res.at("/query/operands/1/key").asText());
+ assertEquals(true, res.at("/query/operands/2").isMissingNode());
+ assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+ assertEquals("koral:term", res.at("/query/relation/wrap/@type")
+ .asText());
+ assertEquals("c", res.at("/query/relation/wrap/layer").asText());
}
+
@Test
- public void testDefPredicationInversion() throws JsonProcessingException, IOException {
- query = "#1 > #2 & cnx/cat=\"vp\" & cnx/cat=\"np\"";
+ public void testDefPredicationInversion () throws JsonProcessingException,
+ IOException {
+ query = "#1 > #2 & cnx/cat=\"vp\" & cnx/cat=\"np\"";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:relation", res.at("/query/operation").asText());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("vp", res.at("/query/operands/0/key").asText());
- assertEquals("c", res.at("/query/operands/0/layer").asText());
- assertEquals("cnx", res.at("/query/operands/0/foundry").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
- assertEquals("np", res.at("/query/operands/1/key").asText());
- assertEquals("c", res.at("/query/operands/1/layer").asText());
- assertEquals("cnx", res.at("/query/operands/1/foundry").asText());
- assertEquals("koral:relation", res.at("/query/relation/@type").asText());
- assertEquals("koral:term", res.at("/query/relation/wrap/@type").asText());
- assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("vp", res.at("/query/operands/0/key").asText());
+ assertEquals("c", res.at("/query/operands/0/layer").asText());
+ assertEquals("cnx", res.at("/query/operands/0/foundry").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("np", res.at("/query/operands/1/key").asText());
+ assertEquals("c", res.at("/query/operands/1/layer").asText());
+ assertEquals("cnx", res.at("/query/operands/1/foundry").asText());
+ assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+ assertEquals("koral:term", res.at("/query/relation/wrap/@type")
+ .asText());
+ assertEquals("c", res.at("/query/relation/wrap/layer").asText());
}
- @Test
- public void testSimpleDominance() throws JsonProcessingException, IOException {
- query = "node & node & #2 > #1";
- qs.setQuery(query, "annis");
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:relation", res.at("/query/operation").asText());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
- assertEquals("koral:relation", res.at("/query/relation/@type").asText());
- assertEquals("koral:term", res.at("/query/relation/wrap/@type").asText());
- assertEquals("c", res.at("/query/relation/wrap/layer").asText());
- query = "\"Mann\" & node & #2 > #1";
+ @Test
+ public void testSimpleDominance () throws JsonProcessingException,
+ IOException {
+ query = "node & node & #2 > #1";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:relation", res.at("/query/operation").asText());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
- assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
- assertEquals("koral:relation", res.at("/query/relation/@type").asText());
- assertEquals("koral:term", res.at("/query/relation/wrap/@type").asText());
- assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+ assertEquals("koral:term", res.at("/query/relation/wrap/@type")
+ .asText());
+ assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+
+ query = "\"Mann\" & node & #2 > #1";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
+ assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+ assertEquals("koral:term", res.at("/query/relation/wrap/@type")
+ .asText());
+ assertEquals("c", res.at("/query/relation/wrap/layer").asText());
query = "\"Mann\" & node & #2 >[func=\"SB\"] #1"; //coordinates the func=SB term and requires a "c"-layer term (consituency relation/dominance)
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:relation", res.at("/query/relation/@type").asText());
- assertEquals("koral:termGroup", res.at("/query/relation/wrap/@type").asText());
- assertEquals("relation:and", res.at("/query/relation/wrap/relation").asText());
- assertEquals("c", res.at("/query/relation/wrap/operands/1/layer").asText());
- assertEquals("func", res.at("/query/relation/wrap/operands/0/layer").asText());
- assertEquals("SB", res.at("/query/relation/wrap/operands/0/key").asText());
+ assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+ assertEquals("koral:termGroup", res.at("/query/relation/wrap/@type")
+ .asText());
+ assertEquals("relation:and", res.at("/query/relation/wrap/relation")
+ .asText());
+ assertEquals("c", res.at("/query/relation/wrap/operands/1/layer")
+ .asText());
+ assertEquals("func", res.at("/query/relation/wrap/operands/0/layer")
+ .asText());
+ assertEquals("SB", res.at("/query/relation/wrap/operands/0/key")
+ .asText());
query = "cat=\"S\" & node & #1 >[func=\"SB\" func=\"MO\"] #2"; // quite meaningless (function is subject and modifier), but this is allowed by Annis, however its backend only regards the 1st option
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:relation", res.at("/query/relation/@type").asText());
- assertEquals("koral:termGroup", res.at("/query/relation/wrap/@type").asText());
- assertEquals("relation:and", res.at("/query/relation/wrap/relation").asText());
- assertEquals("func", res.at("/query/relation/wrap/operands/0/layer").asText());
- assertEquals("SB", res.at("/query/relation/wrap/operands/0/key").asText());
- assertEquals("func", res.at("/query/relation/wrap/operands/1/layer").asText());
- assertEquals("MO" , res.at("/query/relation/wrap/operands/1/key").asText());
- assertEquals("c", res.at("/query/relation/wrap/operands/2/layer").asText());
+ assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+ assertEquals("koral:termGroup", res.at("/query/relation/wrap/@type")
+ .asText());
+ assertEquals("relation:and", res.at("/query/relation/wrap/relation")
+ .asText());
+ assertEquals("func", res.at("/query/relation/wrap/operands/0/layer")
+ .asText());
+ assertEquals("SB", res.at("/query/relation/wrap/operands/0/key")
+ .asText());
+ assertEquals("func", res.at("/query/relation/wrap/operands/1/layer")
+ .asText());
+ assertEquals("MO", res.at("/query/relation/wrap/operands/1/key")
+ .asText());
+ assertEquals("c", res.at("/query/relation/wrap/operands/2/layer")
+ .asText());
query = "cat=\"S\" & cat=\"NP\" & #1 >@l #2"; // all sentences starting with NP -> wrap relation in startswith and retrieve 2nd operand with focus
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("operation:position", res.at("/query/operation").asText());
- assertEquals("operation:relation", res.at("/query/operands/0/operation").asText());
- assertEquals("frames:startsWith", res.at("/query/frames/0").asText());
- assertEquals("koral:span", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("S", res.at("/query/operands/0/operands/0/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
- assertEquals(130, res.at("/query/operands/0/operands/1/classOut").asInt());
- assertEquals("koral:span", res.at("/query/operands/0/operands/1/operands/0/@type").asText());
- assertEquals("NP", res.at("/query/operands/0/operands/1/operands/0/key").asText());
- assertEquals("koral:reference", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/1/operation").asText());
- assertEquals(130, res.at("/query/operands/1/classRef/0").asInt());
+ assertEquals("operation:position", res.at("/query/operation").asText());
+ assertEquals("operation:relation", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("frames:startsWith", res.at("/query/frames/0").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("S", res.at("/query/operands/0/operands/0/key").asText());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/1/@type").asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/1/operation").asText());
+ assertEquals(130, res.at("/query/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals("koral:span",
+ res.at("/query/operands/0/operands/1/operands/0/@type")
+ .asText());
+ assertEquals("NP", res
+ .at("/query/operands/0/operands/1/operands/0/key").asText());
+ assertEquals("koral:reference", res.at("/query/operands/1/@type")
+ .asText());
+ assertEquals("operation:focus", res.at("/query/operands/1/operation")
+ .asText());
+ assertEquals(130, res.at("/query/operands/1/classRef/0").asInt());
- query = "cat=\"S\" & cat=\"NP\" & #1 >@r #2";
+ query = "cat=\"S\" & cat=\"NP\" & #1 >@r #2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("operation:position", res.at("/query/operation").asText());
- assertEquals("operation:relation", res.at("/query/operands/0/operation").asText());
- assertEquals("frames:endsWith", res.at("/query/frames/0").asText());
- assertEquals("koral:span", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("S", res.at("/query/operands/0/operands/0/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
- assertEquals(130, res.at("/query/operands/0/operands/1/classOut").asInt());
- assertEquals("koral:span", res.at("/query/operands/0/operands/1/operands/0/@type").asText());
- assertEquals("NP", res.at("/query/operands/0/operands/1/operands/0/key").asText());
- assertEquals("koral:reference", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/1/operation").asText());
- assertEquals(130, res.at("/query/operands/1/classRef/0").asInt());
- }
-
- @Test
- public void testIndirectDominance() throws JsonProcessingException, IOException {
- query = "node & node & #1 >2,4 #2";
- qs.setQuery(query, "annis");
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:relation", res.at("/query/operation").asText());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
- assertEquals("koral:relation", res.at("/query/relation/@type").asText());
- assertEquals(2, res.at("/query/relation/boundary/min").asInt());
- assertEquals(4, res.at("/query/relation/boundary/max").asInt());
- assertEquals("koral:term", res.at("/query/relation/wrap/@type").asText());
- assertEquals("c", res.at("/query/relation/wrap/layer").asText());
-
- query = "node & node & #1 >* #2";
- qs.setQuery(query, "annis");
- res = mapper.readTree(qs.toJSON());
- assertEquals(0, res.at("/query/relation/boundary/min").asInt());
- assertEquals(true, res.at("/query/relation/boundary/max").isMissingNode());
+ assertEquals("operation:position", res.at("/query/operation").asText());
+ assertEquals("operation:relation", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("frames:endsWith", res.at("/query/frames/0").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("S", res.at("/query/operands/0/operands/0/key").asText());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/1/@type").asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/1/operation").asText());
+ assertEquals(130, res.at("/query/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals("koral:span",
+ res.at("/query/operands/0/operands/1/operands/0/@type")
+ .asText());
+ assertEquals("NP", res
+ .at("/query/operands/0/operands/1/operands/0/key").asText());
+ assertEquals("koral:reference", res.at("/query/operands/1/@type")
+ .asText());
+ assertEquals("operation:focus", res.at("/query/operands/1/operation")
+ .asText());
+ assertEquals(130, res.at("/query/operands/1/classRef/0").asInt());
}
@Test
- public void testMultipleDominance() throws JsonProcessingException, IOException {
- query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & #1 > #2 > #3";
+ public void testIndirectDominance () throws JsonProcessingException,
+ IOException {
+ query = "node & node & #1 >2,4 #2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:relation", res.at("/query/operation").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("koral:relation", res.at("/query/operands/0/operands/0/relation/@type").asText());
- assertEquals("c", res.at("/query/operands/0/operands/0/relation/wrap/layer").asText());
- assertEquals("koral:span", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("c", res.at("/query/operands/0/operands/0/operands/0/layer").asText());
- assertEquals("CP", res.at("/query/operands/0/operands/0/operands/0/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
- assertEquals("VP", res.at("/query/operands/0/operands/0/operands/1/operands/0/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+ assertEquals(2, res.at("/query/relation/boundary/min").asInt());
+ assertEquals(4, res.at("/query/relation/boundary/max").asInt());
+ assertEquals("koral:term", res.at("/query/relation/wrap/@type")
+ .asText());
+ assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+
+ query = "node & node & #1 >* #2";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals(0, res.at("/query/relation/boundary/min").asInt());
+ assertEquals(true, res.at("/query/relation/boundary/max")
+ .isMissingNode());
}
+
+
+ @Test
+ public void testMultipleDominance () throws JsonProcessingException,
+ IOException {
+ query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & #1 > #2 > #3";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("koral:reference", res.at("/query/operands/0/@type")
+ .asText());
+ assertEquals("operation:focus", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:relation",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("koral:relation",
+ res.at("/query/operands/0/operands/0/relation/@type").asText());
+ assertEquals("c",
+ res.at("/query/operands/0/operands/0/relation/wrap/layer")
+ .asText());
+ assertEquals("koral:span",
+ res.at("/query/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("c",
+ res.at("/query/operands/0/operands/0/operands/0/layer")
+ .asText());
+ assertEquals("CP", res
+ .at("/query/operands/0/operands/0/operands/0/key").asText());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/0/operands/1/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "VP",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/key")
+ .asText());
+ }
+
+
// query = "cat=\"CP\" & cat=\"VP\" & cat=\"NP\" & #1 > #2 > #3";
// String dom1 =
// "{@type=koral:group, operation=operation:relation, operands=[" +
@@ -402,100 +482,114 @@
// }
@Test
- public void testSequence() throws Exception {
+ public void testSequence () throws Exception {
query = "tok=\"der\" & tok=\"die\" & #1 . #2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("die", res.at("/query/operands/1/wrap/key").asText());
- assertEquals(true, res.at("/query/inOrder").asBoolean());
- assertEquals(true, res.at("/query/operands/2").isMissingNode());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("die", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals(true, res.at("/query/inOrder").asBoolean());
+ assertEquals(true, res.at("/query/operands/2").isMissingNode());
query = "tok=\"der\" & tok=\"die\" & #1 .2,3 #2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("die", res.at("/query/operands/1/wrap/key").asText());
- assertEquals(true, res.at("/query/inOrder").asBoolean());
- assertEquals(true, res.at("/query/operands/2").isMissingNode());
- assertEquals("koral:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("koral:boundary", res.at("/query/distances/0/boundary/@type").asText());
- assertEquals(1, res.at("/query/distances/0/boundary/min").asInt());
- assertEquals(2, res.at("/query/distances/0/boundary/max").asInt());
-
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("die", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals(true, res.at("/query/inOrder").asBoolean());
+ assertEquals(true, res.at("/query/operands/2").isMissingNode());
+ assertEquals("koral:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("koral:boundary",
+ res.at("/query/distances/0/boundary/@type").asText());
+ assertEquals(1, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(2, res.at("/query/distances/0/boundary/max").asInt());
+
query = "tok=\"der\" & tok=\"die\" & #1 .2 #2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("die", res.at("/query/operands/1/wrap/key").asText());
- assertEquals(true, res.at("/query/inOrder").asBoolean());
- assertEquals(true, res.at("/query/operands/2").isMissingNode());
- assertEquals("koral:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("koral:boundary", res.at("/query/distances/0/boundary/@type").asText());
- assertEquals(1, res.at("/query/distances/0/boundary/min").asInt());
- assertEquals(true, res.at("/query/distances/0/boundary/max").isMissingNode());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("die", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals(true, res.at("/query/inOrder").asBoolean());
+ assertEquals(true, res.at("/query/operands/2").isMissingNode());
+ assertEquals("koral:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("koral:boundary",
+ res.at("/query/distances/0/boundary/@type").asText());
+ assertEquals(1, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(true, res.at("/query/distances/0/boundary/max")
+ .isMissingNode());
query = "tok=\"der\" & tok=\"die\" & #1 .* #2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:boundary", res.at("/query/distances/0/boundary/@type").asText());
- assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
- assertEquals(true, res.at("/query/distances/0/boundary/max").isMissingNode());
+ assertEquals("koral:boundary",
+ res.at("/query/distances/0/boundary/@type").asText());
+ assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(true, res.at("/query/distances/0/boundary/max")
+ .isMissingNode());
}
+
@Test
- public void testNear() throws Exception {
+ public void testNear () throws Exception {
query = "tok=\"der\" & tok=\"die\" & #1 ^ #2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("die", res.at("/query/operands/1/wrap/key").asText());
- assertEquals(false, res.at("/query/inOrder").asBoolean());
- assertEquals(true, res.at("/query/operands/2").isMissingNode());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("die", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals(false, res.at("/query/inOrder").asBoolean());
+ assertEquals(true, res.at("/query/operands/2").isMissingNode());
query = "tok=\"der\" & tok=\"die\" & #1 ^2,3 #2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("die", res.at("/query/operands/1/wrap/key").asText());
- assertEquals(false, res.at("/query/inOrder").asBoolean());
- assertEquals(true, res.at("/query/operands/2").isMissingNode());
- assertEquals("koral:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("koral:boundary", res.at("/query/distances/0/boundary/@type").asText());
- assertEquals(1, res.at("/query/distances/0/boundary/min").asInt());
- assertEquals(2, res.at("/query/distances/0/boundary/max").asInt());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("die", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals(false, res.at("/query/inOrder").asBoolean());
+ assertEquals(true, res.at("/query/operands/2").isMissingNode());
+ assertEquals("koral:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("koral:boundary",
+ res.at("/query/distances/0/boundary/@type").asText());
+ assertEquals(1, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(2, res.at("/query/distances/0/boundary/max").asInt());
query = "tok=\"der\" & tok=\"die\" & #1 ^* #2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:boundary", res.at("/query/distances/0/boundary/@type").asText());
- assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
- assertEquals(true, res.at("/query/distances/0/boundary/max").isMissingNode());
- assertEquals(false, res.at("/query/inOrder").asBoolean());
+ assertEquals("koral:boundary",
+ res.at("/query/distances/0/boundary/@type").asText());
+ assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(true, res.at("/query/distances/0/boundary/max")
+ .isMissingNode());
+ assertEquals(false, res.at("/query/inOrder").asBoolean());
}
@Test
- public void testMultipleSequence() throws Exception {
+ public void testMultipleSequence () throws Exception {
query = "tok=\"a\" & tok=\"b\" & tok=\"c\" & #1 . #2 & #2 . #3";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/@type").asText());
- assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
- assertEquals(res.at("/query/operands/0/classRef/0").asInt(),
- res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("koral:reference", res.at("/query/operands/0/@type")
+ .asText());
+ assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
+ assertEquals(res.at("/query/operands/0/classRef/0").asInt(),
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
}
@@ -550,442 +644,731 @@
// }
//
/**
- * Tests the (rather difficult) serialization of queries where two subsequent relations
- * do not share any common operand. Makes it impossible to wrap 2nd relation around 1st.
- * Must therefore re-order relations (or postpone processing of 2nd).
+ * Tests the (rather difficult) serialization of queries where two
+ * subsequent relations
+ * do not share any common operand. Makes it impossible to wrap
+ * 2nd relation around 1st.
+ * Must therefore re-order relations (or postpone processing of
+ * 2nd).
+ *
* @throws JsonProcessingException
* @throws IOException
*/
@Test
- public void testNoSharedOperand() throws JsonProcessingException, IOException {
- query = "cat=\"A\" & cat=\"B\" & cat=\"C\" & cat=\"D\" & #1 . #2 & #3 . #4 & #1 > #3";
+ public void testNoSharedOperand () throws JsonProcessingException,
+ IOException {
+ query = "cat=\"A\" & cat=\"B\" & cat=\"C\" & cat=\"D\" & #1 . #2 & #3 . #4 & #1 > #3";
// the resulting query should be equivalent to PQ+: focus(2:dominates(focus(1:{1:<A>}<B>),{2:<C>}))<D>
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operands/0/operands/0/operation").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operands/0/operands/0/operands/0/operands/0/operation").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operation").asText());
- assertEquals("A", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/key").asText());
- assertEquals("B", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/key").asText());
- assertEquals("C", res.at("/query/operands/0/operands/0/operands/1/operands/0/key").asText());
- assertEquals("D", res.at("/query/operands/1/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("koral:reference", res.at("/query/operands/0/@type")
+ .asText());
+ assertEquals("operation:focus", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:relation",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("koral:reference",
+ res.at("/query/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("operation:focus",
+ res.at("/query/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(
+ "koral:group",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals(
+ "operation:sequence",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(
+ "operation:class",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(
+ "A",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/key")
+ .asText());
+ assertEquals(
+ "B",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/key")
+ .asText());
+ assertEquals(
+ "C",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/key")
+ .asText());
+ assertEquals("D", res.at("/query/operands/1/key").asText());
- query = "cat=\"A\" & cat=\"B\" & cat=\"C\" & cat=\"D\" & cat=\"E\" & cat=\"F\" & #1 . #2 & #3 . #4 & #5 . #6 & #1 > #3 & #3 > #5";
+ query = "cat=\"A\" & cat=\"B\" & cat=\"C\" & cat=\"D\" & cat=\"E\" & cat=\"F\" & #1 . #2 & #3 . #4 & #5 . #6 & #1 > #3 & #3 > #5";
// the resulting query should be equivalent to PQ+: focus(3:dominates(focus(2:dominates(focus(1:{1:<A>}<B>),{2:<C>}))<D>,{3:<E>}))<F>
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operands/0/operands/0/operation").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operands/0/operands/0/operands/0/operands/0/operation").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operation").asText());
- assertEquals("A", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/key").asText());
- assertEquals("B", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/1/key").asText());
- assertEquals("C", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/1/operands/0/key").asText());
- assertEquals("D", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/key").asText());
- assertEquals("E", res.at("/query/operands/0/operands/0/operands/1/operands/0/key").asText());
- assertEquals("F", res.at("/query/operands/1/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("koral:reference", res.at("/query/operands/0/@type")
+ .asText());
+ assertEquals("operation:focus", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:relation",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("koral:reference",
+ res.at("/query/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("operation:focus",
+ res.at("/query/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(
+ "koral:group",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals(
+ "operation:sequence",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(
+ "operation:class",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(
+ "A",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/key")
+ .asText());
+ assertEquals(
+ "B",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/1/key")
+ .asText());
+ assertEquals(
+ "C",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/operands/1/operands/0/key")
+ .asText());
+ assertEquals(
+ "D",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/key")
+ .asText());
+ assertEquals(
+ "E",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/key")
+ .asText());
+ assertEquals("F", res.at("/query/operands/1/key").asText());
- query = "cat=\"A\" & cat=\"B\" & cat=\"C\" & cat=\"D\" & #1 . #2 & #3 . #4";
+ query = "cat=\"A\" & cat=\"B\" & cat=\"C\" & cat=\"D\" & #1 . #2 & #3 . #4";
// the resulting query should be equivalent to PQ+: focus(2:dominates(focus(1:{1:<A>}<B>),{2:<C>}))<D>
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals(true, res.at("/query/@type").isMissingNode());
- assertEquals(StatusCodes.UNBOUND_ANNIS_RELATION, res.at("/errors/0/0").asInt());
+ assertEquals(true, res.at("/query/@type").isMissingNode());
+ assertEquals(StatusCodes.UNBOUND_ANNIS_RELATION, res.at("/errors/0/0")
+ .asInt());
}
+
@Test
- public void testMultipleMixedOperators() throws Exception {
+ public void testMultipleMixedOperators () throws Exception {
query = "tok=\"Sonne\" & tok=\"Mond\" & tok=\"Sterne\" & #1 > #2 .1,4 #3";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("koral:token", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("Sonne", res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
- assertEquals("Mond", res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
- assertEquals("Sterne", res.at("/query/operands/1/wrap/key").asText());
- assertEquals("w", res.at("/query/distances/0/key").asText());
- assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
- assertEquals(3, res.at("/query/distances/0/boundary/max").asInt());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("koral:reference", res.at("/query/operands/0/@type")
+ .asText());
+ assertEquals("operation:focus", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:relation",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("koral:token",
+ res.at("/query/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("Sonne",
+ res.at("/query/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/0/operands/1/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "Mond",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("Sterne", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("w", res.at("/query/distances/0/key").asText());
+ assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(3, res.at("/query/distances/0/boundary/max").asInt());
query = "tok=\"Sonne\" & tok=\"Mond\" & #1 > #2 .1,4 tok=\"Sterne\"";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("koral:token", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("Sonne", res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
- assertEquals("Mond", res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
- assertEquals("Sterne", res.at("/query/operands/1/wrap/key").asText());
- assertEquals("w", res.at("/query/distances/0/key").asText());
- assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
- assertEquals(3, res.at("/query/distances/0/boundary/max").asInt());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("koral:reference", res.at("/query/operands/0/@type")
+ .asText());
+ assertEquals("operation:focus", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:relation",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("koral:token",
+ res.at("/query/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("Sonne",
+ res.at("/query/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/0/operands/1/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "Mond",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("Sterne", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("w", res.at("/query/distances/0/key").asText());
+ assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(3, res.at("/query/distances/0/boundary/max").asInt());
query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 > #3";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:relation", res.at("/query/operation").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
- assertEquals(130, res.at("/query/operands/0/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operands/0/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/operands/0/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operands/0/operands/0/operation").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/classOut").asInt());
- assertEquals("koral:span", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("NP", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
- assertEquals(130, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
- assertEquals("VP", res.at("/query/operands/0/operands/0/operands/1/operands/0/key").asText());
- assertEquals("PP", res.at("/query/operands/1/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("koral:reference", res.at("/query/operands/0/@type")
+ .asText());
+ assertEquals("operation:focus", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(130, res.at("/query/operands/0/classRef/0").asInt());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:relation",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("koral:reference",
+ res.at("/query/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("operation:focus",
+ res.at("/query/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/0/operands/0/classRef/0")
+ .asInt());
+ assertEquals(
+ "koral:group",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals(
+ "operation:relation",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(
+ "operation:class",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(
+ 129,
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/classOut")
+ .asInt());
+ assertEquals(
+ "koral:span",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals(
+ "NP",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/key")
+ .asText());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/0/operands/1/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(130,
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "VP",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/key")
+ .asText());
+ assertEquals("PP", res.at("/query/operands/1/key").asText());
}
+
+
@Test
- public void testMultipleOperatorsWithSameOperands() throws Exception {
+ public void testMultipleOperatorsWithSameOperands () throws Exception {
query = "cat=\"NP\" > cat=\"VP\" & #1 _l_ #2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:position", res.at("/query/operation").asText());
- assertEquals("frames:startsWith", res.at("/query/frames/0").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/operands/0/classOut").asInt());
- assertEquals("koral:span", res.at("/query/operands/0/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("NP", res.at("/query/operands/0/operands/0/operands/0/operands/0/key").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
- assertEquals(130, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
- assertEquals("VP", res.at("/query/operands/0/operands/0/operands/1/operands/0/key").asText());
- assertEquals("koral:reference", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/1/operation").asText());
- assertEquals(130, res.at("/query/operands/1/classRef/0").asInt());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:position", res.at("/query/operation").asText());
+ assertEquals("frames:startsWith", res.at("/query/frames/0").asText());
+ assertEquals("koral:reference", res.at("/query/operands/0/@type")
+ .asText());
+ assertEquals("operation:focus", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:relation",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/0/operands/0/classOut")
+ .asInt());
+ assertEquals(
+ "koral:span",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals(
+ "NP",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/key")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(130,
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "VP",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/key")
+ .asText());
+ assertEquals("koral:reference", res.at("/query/operands/1/@type")
+ .asText());
+ assertEquals("operation:focus", res.at("/query/operands/1/operation")
+ .asText());
+ assertEquals(130, res.at("/query/operands/1/classRef/0").asInt());
}
+
+
@Test
- public void testPositions() throws Exception {
+ public void testPositions () throws Exception {
query = "node & node & #1 _=_ #2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:position", res.at("/query/operation").asText());
- assertEquals("frames:matches", res.at("/query/frames/0").asText());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:position", res.at("/query/operation").asText());
+ assertEquals("frames:matches", res.at("/query/frames/0").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
query = "node & node & #1 _i_ #2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("frames:isAround", res.at("/query/frames/0").asText());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("frames:isAround", res.at("/query/frames/0").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
query = "node & node & #1 _l_ #2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("frames:startsWith", res.at("/query/frames/0").asText());
- assertEquals("frames:matches", res.at("/query/frames/1").asText());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("frames:startsWith", res.at("/query/frames/0").asText());
+ assertEquals("frames:matches", res.at("/query/frames/1").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
query = "node & node & #1 _r_ #2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("frames:endsWith", res.at("/query/frames/0").asText());
- assertEquals("frames:matches", res.at("/query/frames/1").asText());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("frames:endsWith", res.at("/query/frames/0").asText());
+ assertEquals("frames:matches", res.at("/query/frames/1").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
query = "node & \"Mann\" & #1 _r_ #2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("frames:endsWith", res.at("/query/frames/0").asText());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
- assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("frames:endsWith", res.at("/query/frames/0").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
+ assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
query = "node & \"Mann\" & #2 _r_ #1";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("frames:endsWith", res.at("/query/frames/0").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
- assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
- assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("frames:endsWith", res.at("/query/frames/0").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+ assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
query = "node & cat=\"VP\" & cat=\"NP\" & #1 _r_ #2 & #2 _l_ #3";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("frames:startsWith", res.at("/query/frames/0").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
- assertEquals("frames:endsWith", res.at("/query/operands/0/operands/0/frames/0").asText());
- assertEquals("koral:span", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
- assertEquals("VP", res.at("/query/operands/0/operands/0/operands/1/operands/0/key").asText());
- assertEquals("NP", res.at("/query/operands/1/key").asText());
+ assertEquals("frames:startsWith", res.at("/query/frames/0").asText());
+ assertEquals("operation:focus", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
+ assertEquals("frames:endsWith",
+ res.at("/query/operands/0/operands/0/frames/0").asText());
+ assertEquals("koral:span",
+ res.at("/query/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/0/operands/1/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "VP",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/key")
+ .asText());
+ assertEquals("NP", res.at("/query/operands/1/key").asText());
query = "node & \"Mann\" & #2 _o_ #1";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("frames:overlapsLeft", res.at("/query/frames/0").asText());
- assertEquals("frames:overlapsRight", res.at("/query/frames/1").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
- assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
- assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("frames:overlapsLeft", res.at("/query/frames/0").asText());
+ assertEquals("frames:overlapsRight", res.at("/query/frames/1").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+ assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
query = "node & \"Mann\" & #2 _ol_ #1";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("frames:overlapsLeft", res.at("/query/frames/0").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
- assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
- assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("frames:overlapsLeft", res.at("/query/frames/0").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+ assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
query = "node & \"Mann\" & #2 _or_ #1";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("frames:overlapsRight", res.at("/query/frames/0").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
- assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
- assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("frames:overlapsRight", res.at("/query/frames/0").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+ assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
}
- @Test
- public void testMultiplePredications() throws Exception {
- // a noun before a verb before a preposition
- query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 . #2 & #2 . #3";
- qs.setQuery(query, "annis");
- res = mapper.readTree(qs.toJSON());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
- assertEquals("operation:sequence", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("koral:token", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("p", res.at("/query/operands/0/operands/0/operands/0/wrap/layer").asText());
- assertEquals("N", res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
- assertEquals("V", res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
- assertEquals("P", res.at("/query/operands/1/wrap/key").asText());
- query = "pos=\"N\" & pos=\"V\" & #1 . #2 & #2 . pos=\"P\"";
+ @Test
+ public void testMultiplePredications () throws Exception {
+ // a noun before a verb before a preposition
+ query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 . #2 & #2 . #3";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
- assertEquals("operation:sequence", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("koral:token", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("p", res.at("/query/operands/0/operands/0/operands/0/wrap/layer").asText());
- assertEquals("N", res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
- assertEquals("V", res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
- assertEquals("P", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("operation:focus", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
+ assertEquals("operation:sequence",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("koral:token",
+ res.at("/query/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("p",
+ res.at("/query/operands/0/operands/0/operands/0/wrap/layer")
+ .asText());
+ assertEquals("N",
+ res.at("/query/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/0/operands/1/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "V",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("P", res.at("/query/operands/1/wrap/key").asText());
+
+ query = "pos=\"N\" & pos=\"V\" & #1 . #2 & #2 . pos=\"P\"";
+ qs.setQuery(query, "annis");
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("operation:focus", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
+ assertEquals("operation:sequence",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("koral:token",
+ res.at("/query/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("p",
+ res.at("/query/operands/0/operands/0/operands/0/wrap/layer")
+ .asText());
+ assertEquals("N",
+ res.at("/query/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/0/operands/1/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "V",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("P", res.at("/query/operands/1/wrap/key").asText());
query = "pos=\"N\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("operation:relation", res.at("/query/operation").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
- assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/operands/0/classOut").asInt());
- assertEquals("N", res.at("/query/operands/0/operands/0/operands/0/operands/0/wrap/key").asText());
- assertEquals("V", res.at("/query/operands/0/operands/0/operands/1/wrap/key").asText());
- assertEquals("P", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("operation:focus", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
+ assertEquals("operation:relation",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/0/operands/0/classOut")
+ .asInt());
+ assertEquals(
+ "N",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("V",
+ res.at("/query/operands/0/operands/0/operands/1/wrap/key")
+ .asText());
+ assertEquals("P", res.at("/query/operands/1/wrap/key").asText());
query = "cat=\"NP\" & pos=\"V\" & pos=\"P\" & #1 > #2 & #1 > #3 & #2 . #3";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
- assertEquals(130, res.at("/query/operands/0/classRef/0").asInt());
- assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operands/0/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/operands/0/classRef/0").asInt());
- assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operands/0/operands/0/operation").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/classOut").asInt());
- assertEquals("NP", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/key").asText());
- assertEquals(130, res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/classOut").asInt());
- assertEquals("V", res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
- assertEquals(131, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
- assertEquals("P", res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
- assertEquals("operation:focus", res.at("/query/operands/1/operation").asText());
- assertEquals(131, res.at("/query/operands/1/classRef/0").asInt());
- assertEquals(true, res.at("/query/operands/1/operands").isMissingNode());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("operation:focus", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(130, res.at("/query/operands/0/classRef/0").asInt());
+ assertEquals("operation:relation",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("operation:focus",
+ res.at("/query/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/0/operands/0/classRef/0")
+ .asInt());
+ assertEquals(
+ "operation:relation",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(
+ "operation:class",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(
+ 129,
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/classOut")
+ .asInt());
+ assertEquals(
+ "NP",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/0/operands/0/key")
+ .asText());
+ assertEquals(
+ 130,
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "V",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals(131,
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "P",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("operation:focus", res.at("/query/operands/1/operation")
+ .asText());
+ assertEquals(131, res.at("/query/operands/1/classRef/0").asInt());
+ assertEquals(true, res.at("/query/operands/1/operands").isMissingNode());
}
+
@Test
- public void testUnaryRelations() throws JsonProcessingException, IOException {
+ public void testUnaryRelations () throws JsonProcessingException,
+ IOException {
query = "node & #1:tokenarity=2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/attr/@type").asText());
- assertEquals("koral:boundary", res.at("/query/attr/tokenarity/@type").asText());
- assertEquals(2, res.at("/query/attr/tokenarity/min").asInt());
- assertEquals(2, res.at("/query/attr/tokenarity/max").asInt());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/attr/@type").asText());
+ assertEquals("koral:boundary", res.at("/query/attr/tokenarity/@type")
+ .asText());
+ assertEquals(2, res.at("/query/attr/tokenarity/min").asInt());
+ assertEquals(2, res.at("/query/attr/tokenarity/max").asInt());
query = "cnx/cat=\"NP\" & #1:tokenarity=2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("cnx", res.at("/query/foundry").asText());
- assertEquals("c", res.at("/query/layer").asText());
- assertEquals("NP", res.at("/query/key").asText());
- assertEquals("koral:term", res.at("/query/attr/@type").asText());
- assertEquals("koral:boundary", res.at("/query/attr/tokenarity/@type").asText());
- assertEquals(2, res.at("/query/attr/tokenarity/min").asInt());
- assertEquals(2, res.at("/query/attr/tokenarity/max").asInt());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("cnx", res.at("/query/foundry").asText());
+ assertEquals("c", res.at("/query/layer").asText());
+ assertEquals("NP", res.at("/query/key").asText());
+ assertEquals("koral:term", res.at("/query/attr/@type").asText());
+ assertEquals("koral:boundary", res.at("/query/attr/tokenarity/@type")
+ .asText());
+ assertEquals(2, res.at("/query/attr/tokenarity/min").asInt());
+ assertEquals(2, res.at("/query/attr/tokenarity/max").asInt());
query = "cnx/cat=\"NP\" & #1:tokenarity=2,5";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals(2, res.at("/query/attr/tokenarity/min").asInt());
- assertEquals(5, res.at("/query/attr/tokenarity/max").asInt());
+ assertEquals(2, res.at("/query/attr/tokenarity/min").asInt());
+ assertEquals(5, res.at("/query/attr/tokenarity/max").asInt());
query = "cnx/cat=\"NP\" & #1:root";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("cnx", res.at("/query/foundry").asText());
- assertEquals("c", res.at("/query/layer").asText());
- assertEquals("NP", res.at("/query/key").asText());
- assertEquals("match:eq", res.at("/query/match").asText());
- assertEquals("koral:term", res.at("/query/attr/@type").asText());
- assertEquals(true, res.at("/query/attr/root").asBoolean());
-
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("cnx", res.at("/query/foundry").asText());
+ assertEquals("c", res.at("/query/layer").asText());
+ assertEquals("NP", res.at("/query/key").asText());
+ assertEquals("match:eq", res.at("/query/match").asText());
+ assertEquals("koral:term", res.at("/query/attr/@type").asText());
+ assertEquals(true, res.at("/query/attr/root").asBoolean());
+
query = "cnx/cat=\"NP\" & #1:root & #1:arity=2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("cnx", res.at("/query/foundry").asText());
- assertEquals("c", res.at("/query/layer").asText());
- assertEquals("NP", res.at("/query/key").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("cnx", res.at("/query/foundry").asText());
+ assertEquals("c", res.at("/query/layer").asText());
+ assertEquals("NP", res.at("/query/key").asText());
assertEquals("koral:termGroup", res.at("/query/attr/@type").asText());
- assertEquals("koral:term", res.at("/query/attr/operands/0/@type").asText());
- assertEquals(true, res.at("/query/attr/operands/0/root").asBoolean());
- assertEquals("koral:term", res.at("/query/attr/operands/1/@type").asText());
- assertEquals("koral:boundary", res.at("/query/attr/operands/1/arity/@type").asText());
- assertEquals(2, res.at("/query/attr/operands/1/arity/min").asInt());
- assertEquals(2, res.at("/query/attr/operands/1/arity/max").asInt());
-
+ assertEquals("koral:term", res.at("/query/attr/operands/0/@type")
+ .asText());
+ assertEquals(true, res.at("/query/attr/operands/0/root").asBoolean());
+ assertEquals("koral:term", res.at("/query/attr/operands/1/@type")
+ .asText());
+ assertEquals("koral:boundary",
+ res.at("/query/attr/operands/1/arity/@type").asText());
+ assertEquals(2, res.at("/query/attr/operands/1/arity/min").asInt());
+ assertEquals(2, res.at("/query/attr/operands/1/arity/max").asInt());
+
query = "cnx/cat=\"NP\" & node & #1>#2 & #1:tokenarity=2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:relation", res.at("/query/operation").asText());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("cnx", res.at("/query/operands/0/foundry").asText());
- assertEquals("c", res.at("/query/operands/0/layer").asText());
- assertEquals("NP", res.at("/query/operands/0/key").asText());
- assertEquals("koral:term", res.at("/query/operands/0/attr/@type").asText());
- assertEquals("koral:boundary", res.at("/query/operands/0/attr/tokenarity/@type").asText());
- assertEquals(2, res.at("/query/operands/0/attr/tokenarity/min").asInt());
- assertEquals(2, res.at("/query/operands/0/attr/tokenarity/max").asInt());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("cnx", res.at("/query/operands/0/foundry").asText());
+ assertEquals("c", res.at("/query/operands/0/layer").asText());
+ assertEquals("NP", res.at("/query/operands/0/key").asText());
+ assertEquals("koral:term", res.at("/query/operands/0/attr/@type")
+ .asText());
+ assertEquals("koral:boundary",
+ res.at("/query/operands/0/attr/tokenarity/@type").asText());
+ assertEquals(2, res.at("/query/operands/0/attr/tokenarity/min").asInt());
+ assertEquals(2, res.at("/query/operands/0/attr/tokenarity/max").asInt());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
}
+
@Test
- public void testCommonParent() throws Exception {
+ public void testCommonParent () throws Exception {
query = "cat=\"NP\" & cat=\"VP\" & #1 $ #2";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:relation", res.at("/query/operation").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/operands/0/classOut").asInt());
- assertEquals("koral:span", res.at("/query/operands/0/operands/0/operands/0/operands/0/@type").asText());
- assertEquals(true, res.at("/query/operands/0/operands/0/operands/0/operands/0/key").isMissingNode());
- assertEquals("koral:span", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
- assertEquals("NP", res.at("/query/operands/0/operands/0/operands/1/key").asText());
- assertEquals("c", res.at("/query/operands/0/operands/0/operands/1/layer").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
- assertEquals("VP", res.at("/query/operands/1/key").asText());
- assertEquals("c", res.at("/query/operands/1/layer").asText());
-
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("koral:reference", res.at("/query/operands/0/@type")
+ .asText());
+ assertEquals("operation:focus", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:relation",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/0/operands/0/classOut")
+ .asInt());
+ assertEquals(
+ "koral:span",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals(
+ true,
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/key")
+ .isMissingNode());
+ assertEquals("koral:span",
+ res.at("/query/operands/0/operands/0/operands/1/@type")
+ .asText());
+ assertEquals("NP", res
+ .at("/query/operands/0/operands/0/operands/1/key").asText());
+ assertEquals("c",
+ res.at("/query/operands/0/operands/0/operands/1/layer")
+ .asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("VP", res.at("/query/operands/1/key").asText());
+ assertEquals("c", res.at("/query/operands/1/layer").asText());
+
query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 $ #3";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:relation", res.at("/query/operation").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:relation", res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("koral:reference", res.at("/query/operands/0/@type")
+ .asText());
+ assertEquals("operation:focus", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/0/classRef/0").asInt());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:relation",
+ res.at("/query/operands/0/operands/0/operation").asText());
}
-
+
+
@Test
- public void testDisjunction() throws Exception {
+ public void testDisjunction () throws Exception {
query = "cat=\"NP\" | cat=\"VP\"";
qs.setQuery(query, "annis");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:disjunction", res.at("/query/operation").asText());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("NP", res.at("/query/operands/0/key").asText());
- assertEquals("c", res.at("/query/operands/0/layer").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
- assertEquals("VP", res.at("/query/operands/1/key").asText());
- assertEquals("c", res.at("/query/operands/1/layer").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:disjunction", res.at("/query/operation")
+ .asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("NP", res.at("/query/operands/0/key").asText());
+ assertEquals("c", res.at("/query/operands/0/layer").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("VP", res.at("/query/operands/1/key").asText());
+ assertEquals("c", res.at("/query/operands/1/layer").asText());
}
-
+
//
// query = "cat=\"NP\" & cat=\"VP\" & cat=\"PP\" & #1 $ #2 $ #3";
// String cp2 =
@@ -1060,16 +1443,15 @@
// }
/*
- @Test
- public void testEqualNotequalValue() throws Exception {
- query = "cat=\"NP\" & cat=\"VP\" & #1 == #2";
- String eq1 =
- "{}"; // ???
- aqlt = new AqlTree(query);
- map = aqlt.getRequestMap().get("query").toString();
- assertEquals(eq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
- }
+ @Test
+ public void testEqualNotequalValue() throws Exception {
+ query = "cat=\"NP\" & cat=\"VP\" & #1 == #2";
+ String eq1 =
+ "{}"; // ???
+ aqlt = new AqlTree(query);
+ map = aqlt.getRequestMap().get("query").toString();
+ assertEquals(eq1.replaceAll(" ", ""), map.replaceAll(" ", ""));
+ }
*/
}
-
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessorTest.java
index a8b9b6e..62e6d1f 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/CollectionQueryProcessorTest.java
@@ -1,4 +1,5 @@
package de.ids_mannheim.korap.query.serialize;
+
import static org.junit.Assert.*;
import java.io.IOException;
@@ -14,366 +15,487 @@
public class CollectionQueryProcessorTest {
- String query = "foo";
- String ql = "poliqarpplus";
- String collection;
- ArrayList<JsonNode> operands;
+ String query = "foo";
+ String ql = "poliqarpplus";
+ String collection;
+ ArrayList<JsonNode> operands;
- QuerySerializer qs = new QuerySerializer();
- ObjectMapper mapper = new ObjectMapper();
- JsonNode res;
-
- @Test
- public void testContext() throws JsonProcessingException, IOException {
- collection = "textClass=politik";
- String contextString = "http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals(contextString, res.get("@context").asText());
- }
-
- @Test
- public void testSimple() throws JsonProcessingException, IOException {
- collection = "textClass=politik";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:doc", res.at("/collection/@type").asText());
- assertEquals("textClass", res.at("/collection/key").asText());
- assertEquals("politik", res.at("/collection/value").asText());
- assertEquals("match:eq", res.at("/collection/match").asText());
-
- collection = "textClass!=politik";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:doc", res.at("/collection/@type").asText());
- assertEquals("textClass", res.at("/collection/key").asText());
- assertEquals("politik", res.at("/collection/value").asText());
- assertEquals("match:ne", res.at("/collection/match").asText());
- }
-
- @Test
- public void testContains() throws JsonProcessingException, IOException {
- collection = "title~Mannheim";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:doc", res.at("/collection/@type").asText());
- assertEquals("title", res.at("/collection/key").asText());
- assertEquals("Mannheim", res.at("/collection/value").asText());
- assertEquals("match:contains", res.at("/collection/match").asText());
-
- collection = "title~\"IDS Mannheim\"";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:doc", res.at("/collection/@type").asText());
- assertEquals("title", res.at("/collection/key").asText());
- assertEquals("IDS Mannheim", res.at("/collection/value").asText());
- assertEquals("match:contains", res.at("/collection/match").asText());
- }
-
- @Test
- public void testTwoConjuncts() throws JsonProcessingException, IOException {
- collection = "textClass=Sport & pubDate in 2014";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:docGroup", res.at("/collection/@type").asText());
- assertEquals("operation:and", res.at("/collection/operation").asText());
- assertEquals("koral:doc", res.at("/collection/operands/0/@type").asText());
- assertEquals("textClass", res.at("/collection/operands/0/key").asText());
- assertEquals("Sport", res.at("/collection/operands/0/value").asText());
- assertEquals("match:eq", res.at("/collection/operands/0/match").asText());
- assertEquals("koral:doc", res.at("/collection/operands/1/@type").asText());
- assertEquals("pubDate", res.at("/collection/operands/1/key").asText());
- assertEquals("2014", res.at("/collection/operands/1/value").asText());
- assertEquals("type:date", res.at("/collection/operands/1/type").asText());
- assertEquals("match:eq", res.at("/collection/operands/1/match").asText());
-
- collection = "textClass=Sport & pubDate=2014";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:docGroup", res.at("/collection/@type").asText());
- assertEquals("operation:and", res.at("/collection/operation").asText());
- assertEquals("koral:doc", res.at("/collection/operands/0/@type").asText());
- assertEquals("textClass", res.at("/collection/operands/0/key").asText());
- assertEquals("Sport", res.at("/collection/operands/0/value").asText());
- assertEquals("match:eq", res.at("/collection/operands/0/match").asText());
- assertEquals("koral:doc", res.at("/collection/operands/1/@type").asText());
- assertEquals("pubDate", res.at("/collection/operands/1/key").asText());
- assertEquals("2014", res.at("/collection/operands/1/value").asText());
- assertEquals(true, res.at("/collection/operands/1/type").isMissingNode());
- assertEquals("match:eq", res.at("/collection/operands/1/match").asText());
- assertTrue(res.at("/warnings/0/0").asText().startsWith("The collection query contains a value that looks like a date"));
- }
+ QuerySerializer qs = new QuerySerializer();
+ ObjectMapper mapper = new ObjectMapper();
+ JsonNode res;
- @Test
- public void testThreeConjuncts() throws JsonProcessingException, IOException {
- collection = "textClass=Sport & pubDate in 2014 & corpusId=WPD";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:docGroup", res.at("/collection/@type").asText());
- assertEquals("operation:and", res.at("/collection/operation").asText());
- assertEquals("koral:doc", res.at("/collection/operands/0/@type").asText());
- assertEquals("textClass", res.at("/collection/operands/0/key").asText());
- assertEquals("Sport", res.at("/collection/operands/0/value").asText());
- assertEquals("match:eq", res.at("/collection/operands/0/match").asText());
- assertEquals("koral:docGroup", res.at("/collection/operands/1/@type").asText());
- assertEquals("operation:and", res.at("/collection/operands/1/operation").asText());
- assertEquals("koral:doc", res.at("/collection/operands/1/operands/0/@type").asText());
- assertEquals("pubDate", res.at("/collection/operands/1/operands/0/key").asText());
- assertEquals("2014", res.at("/collection/operands/1/operands/0/value").asText());
- assertEquals("type:date", res.at("/collection/operands/1/operands/0/type").asText());
- assertEquals("match:eq", res.at("/collection/operands/1/operands/0/match").asText());
- assertEquals("koral:doc", res.at("/collection/operands/1/operands/1/@type").asText());
- assertEquals("corpusId", res.at("/collection/operands/1/operands/1/key").asText());
- assertEquals("WPD", res.at("/collection/operands/1/operands/1/value").asText());
- assertEquals("match:eq", res.at("/collection/operands/1/operands/1/match").asText());
- }
- @Test
- public void testTwoDisjuncts() throws JsonProcessingException, IOException {
- collection = "textClass=Sport | pubDate in 2014";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:docGroup", res.at("/collection/@type").asText());
- assertEquals("operation:or", res.at("/collection/operation").asText());
- assertEquals("koral:doc", res.at("/collection/operands/0/@type").asText());
- assertEquals("textClass", res.at("/collection/operands/0/key").asText());
- assertEquals("Sport", res.at("/collection/operands/0/value").asText());
- assertEquals("match:eq", res.at("/collection/operands/0/match").asText());
- assertEquals("koral:doc", res.at("/collection/operands/1/@type").asText());
- assertEquals("pubDate", res.at("/collection/operands/1/key").asText());
- assertEquals("2014", res.at("/collection/operands/1/value").asText());
- assertEquals("type:date", res.at("/collection/operands/1/type").asText());
- assertEquals("match:eq", res.at("/collection/operands/1/match").asText());
- }
-
- @Test
- public void testThreeDisjuncts() throws JsonProcessingException, IOException {
- collection = "textClass=Sport | pubDate in 2014 | corpusId=WPD";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:docGroup", res.at("/collection/@type").asText());
- assertEquals("operation:or", res.at("/collection/operation").asText());
- assertEquals("koral:doc", res.at("/collection/operands/0/@type").asText());
- assertEquals("textClass", res.at("/collection/operands/0/key").asText());
- assertEquals("Sport", res.at("/collection/operands/0/value").asText());
- assertEquals("match:eq", res.at("/collection/operands/0/match").asText());
- assertEquals("koral:docGroup", res.at("/collection/operands/1/@type").asText());
- assertEquals("operation:or", res.at("/collection/operands/1/operation").asText());
- assertEquals("koral:doc", res.at("/collection/operands/1/operands/0/@type").asText());
- assertEquals("pubDate", res.at("/collection/operands/1/operands/0/key").asText());
- assertEquals("2014", res.at("/collection/operands/1/operands/0/value").asText());
- assertEquals("type:date", res.at("/collection/operands/1/operands/0/type").asText());
- assertEquals("match:eq", res.at("/collection/operands/1/operands/0/match").asText());
- assertEquals("koral:doc", res.at("/collection/operands/1/operands/1/@type").asText());
- assertEquals("corpusId", res.at("/collection/operands/1/operands/1/key").asText());
- assertEquals("WPD", res.at("/collection/operands/1/operands/1/value").asText());
- assertEquals("match:eq", res.at("/collection/operands/1/operands/1/match").asText());
- }
-
- @Test
- public void testMixed() throws JsonProcessingException, IOException {
- collection = "textClass=Sport | (pubDate in 2014 & corpusId=WPD)";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:docGroup", res.at("/collection/@type").asText());
- assertEquals("operation:or", res.at("/collection/operation").asText());
- assertEquals("koral:doc", res.at("/collection/operands/0/@type").asText());
- assertEquals("textClass", res.at("/collection/operands/0/key").asText());
- assertEquals("Sport", res.at("/collection/operands/0/value").asText());
- assertEquals("match:eq", res.at("/collection/operands/0/match").asText());
- assertEquals("koral:docGroup", res.at("/collection/operands/1/@type").asText());
- assertEquals("operation:and", res.at("/collection/operands/1/operation").asText());
- assertEquals("koral:doc", res.at("/collection/operands/1/operands/0/@type").asText());
- assertEquals("pubDate", res.at("/collection/operands/1/operands/0/key").asText());
- assertEquals("2014", res.at("/collection/operands/1/operands/0/value").asText());
- assertEquals("type:date", res.at("/collection/operands/1/operands/0/type").asText());
- assertEquals("match:eq", res.at("/collection/operands/1/operands/0/match").asText());
- assertEquals("koral:doc", res.at("/collection/operands/1/operands/1/@type").asText());
- assertEquals("corpusId", res.at("/collection/operands/1/operands/1/key").asText());
- assertEquals("WPD", res.at("/collection/operands/1/operands/1/value").asText());
- assertEquals("match:eq", res.at("/collection/operands/1/operands/1/match").asText());
-
- collection = "textClass=Sport | pubDate in 2014 & corpusId=WPD";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:docGroup", res.at("/collection/@type").asText());
- assertEquals("operation:or", res.at("/collection/operation").asText());
- assertEquals("koral:doc", res.at("/collection/operands/0/@type").asText());
- assertEquals("textClass", res.at("/collection/operands/0/key").asText());
- assertEquals("Sport", res.at("/collection/operands/0/value").asText());
- assertEquals("match:eq", res.at("/collection/operands/0/match").asText());
- assertEquals("koral:docGroup", res.at("/collection/operands/1/@type").asText());
- assertEquals("operation:and", res.at("/collection/operands/1/operation").asText());
- assertEquals("koral:doc", res.at("/collection/operands/1/operands/0/@type").asText());
- assertEquals("pubDate", res.at("/collection/operands/1/operands/0/key").asText());
- assertEquals("2014", res.at("/collection/operands/1/operands/0/value").asText());
- assertEquals("type:date", res.at("/collection/operands/1/operands/0/type").asText());
- assertEquals("match:eq", res.at("/collection/operands/1/operands/0/match").asText());
- assertEquals("koral:doc", res.at("/collection/operands/1/operands/1/@type").asText());
- assertEquals("corpusId", res.at("/collection/operands/1/operands/1/key").asText());
- assertEquals("WPD", res.at("/collection/operands/1/operands/1/value").asText());
- assertEquals("match:eq", res.at("/collection/operands/1/operands/1/match").asText());
-
- collection = "(textClass=Sport | pubDate in 2014) & corpusId=WPD";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:docGroup", res.at("/collection/@type").asText());
- assertEquals("operation:and", res.at("/collection/operation").asText());
- assertEquals("koral:docGroup", res.at("/collection/operands/0/@type").asText());
- assertEquals("operation:or", res.at("/collection/operands/0/operation").asText());
- assertEquals("koral:doc", res.at("/collection/operands/0/operands/0/@type").asText());
- assertEquals("koral:doc", res.at("/collection/operands/0/operands/1/@type").asText());
- assertEquals("koral:doc", res.at("/collection/operands/1/@type").asText());
-
- collection = "(textClass=Sport & pubDate in 2014) & corpusId=WPD";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:docGroup", res.at("/collection/@type").asText());
- assertEquals("operation:and", res.at("/collection/operation").asText());
- assertEquals("koral:docGroup", res.at("/collection/operands/0/@type").asText());
- assertEquals("operation:and", res.at("/collection/operands/0/operation").asText());
- assertEquals("koral:doc", res.at("/collection/operands/0/operands/0/@type").asText());
- assertEquals("koral:doc", res.at("/collection/operands/0/operands/1/@type").asText());
- assertEquals("koral:doc", res.at("/collection/operands/1/@type").asText());
-
- collection = "(textClass=Sport & textClass=ausland) | (corpusID=WPD & author=White)";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:docGroup", res.at("/collection/@type").asText());
- assertEquals("operation:or", res.at("/collection/operation").asText());
- assertEquals("koral:docGroup", res.at("/collection/operands/0/@type").asText());
- assertEquals("operation:and", res.at("/collection/operands/0/operation").asText());
- assertEquals("koral:docGroup", res.at("/collection/operands/1/@type").asText());
- assertEquals("operation:and", res.at("/collection/operands/1/operation").asText());
- assertEquals("koral:doc", res.at("/collection/operands/0/operands/0/@type").asText());
- assertEquals("Sport", res.at("/collection/operands/0/operands/0/value").asText());
- assertEquals("koral:doc", res.at("/collection/operands/0/operands/1/@type").asText());
- assertEquals("ausland", res.at("/collection/operands/0/operands/1/value").asText());
- assertEquals("koral:doc", res.at("/collection/operands/1/operands/0/@type").asText());
- assertEquals("WPD", res.at("/collection/operands/1/operands/0/value").asText());
- assertEquals("koral:doc", res.at("/collection/operands/1/operands/1/@type").asText());
- assertEquals("White", res.at("/collection/operands/1/operands/1/value").asText());
-
- collection = "(textClass=Sport & textClass=ausland) | (corpusID=WPD & author=White & pubDate in 2000)";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:docGroup", res.at("/collection/@type").asText());
- assertEquals("operation:or", res.at("/collection/operation").asText());
- assertEquals("koral:docGroup", res.at("/collection/operands/0/@type").asText());
- assertEquals("operation:and", res.at("/collection/operands/0/operation").asText());
- assertEquals("koral:docGroup", res.at("/collection/operands/1/@type").asText());
- assertEquals("operation:and", res.at("/collection/operands/1/operation").asText());
- assertEquals("koral:doc", res.at("/collection/operands/0/operands/0/@type").asText());
- assertEquals("Sport", res.at("/collection/operands/0/operands/0/value").asText());
- assertEquals("koral:doc", res.at("/collection/operands/0/operands/1/@type").asText());
- assertEquals("ausland", res.at("/collection/operands/0/operands/1/value").asText());
- assertEquals("koral:doc", res.at("/collection/operands/1/operands/0/@type").asText());
- assertEquals("WPD", res.at("/collection/operands/1/operands/0/value").asText());
- assertEquals("koral:docGroup", res.at("/collection/operands/1/operands/1/@type").asText());
- assertEquals("operation:and", res.at("/collection/operands/1/operands/1/operation").asText());
- assertEquals("White", res.at("/collection/operands/1/operands/1/operands/0/value").asText());
- assertEquals("2000", res.at("/collection/operands/1/operands/1/operands/1/value").asText());
- }
- @Test
- public void testDateYear() throws JsonProcessingException, IOException {
- collection = "pubDate in 2000";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:doc", res.at("/collection/@type").asText());
- assertEquals("pubDate", res.at("/collection/key").asText());
- assertEquals("2000", res.at("/collection/value").asText());
- assertEquals("type:date", res.at("/collection/type").asText());
- assertEquals("match:eq", res.at("/collection/match").asText());
-
- collection = "pubDate = 2000";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:doc", res.at("/collection/@type").asText());
- assertEquals("pubDate", res.at("/collection/key").asText());
- assertEquals("2000", res.at("/collection/value").asText());
- assertEquals(true, res.at("/collection/type").isMissingNode());
- assertEquals("match:eq", res.at("/collection/match").asText());
-
- collection = "pubDate since 2000";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:doc", res.at("/collection/@type").asText());
- assertEquals("pubDate", res.at("/collection/key").asText());
- assertEquals("2000", res.at("/collection/value").asText());
- assertEquals("type:date", res.at("/collection/type").asText());
- assertEquals("match:geq", res.at("/collection/match").asText());
-
- collection = "pubDate until 2000";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:doc", res.at("/collection/@type").asText());
- assertEquals("pubDate", res.at("/collection/key").asText());
- assertEquals("2000", res.at("/collection/value").asText());
- assertEquals("type:date", res.at("/collection/type").asText());
- assertEquals("match:leq", res.at("/collection/match").asText());
- }
-
- @Test
- public void testDateMonthDay() throws JsonProcessingException, IOException {
- collection = "pubDate in 2000-02";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:doc", res.at("/collection/@type").asText());
- assertEquals("pubDate", res.at("/collection/key").asText());
- assertEquals("2000-02", res.at("/collection/value").asText());
- assertEquals("type:date", res.at("/collection/type").asText());
- assertEquals("match:eq", res.at("/collection/match").asText());
-
- collection = "pubDate = 2000-12";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:doc", res.at("/collection/@type").asText());
- assertEquals("pubDate", res.at("/collection/key").asText());
- assertEquals("2000-12", res.at("/collection/value").asText());
- assertEquals(true, res.at("/collection/type").isMissingNode());
- assertEquals("match:eq", res.at("/collection/match").asText());
-
- collection = "pubDate since 2000-02-01";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:doc", res.at("/collection/@type").asText());
- assertEquals("pubDate", res.at("/collection/key").asText());
- assertEquals("2000-02-01", res.at("/collection/value").asText());
- assertEquals("type:date", res.at("/collection/type").asText());
- assertEquals("match:geq", res.at("/collection/match").asText());
-
- collection = "pubDate until 2000-01-01";
- qs.setQuery(query,ql);
- qs.setCollection(collection);
- res = mapper.readTree(qs.toJSON());
- assertEquals("koral:doc", res.at("/collection/@type").asText());
- assertEquals("pubDate", res.at("/collection/key").asText());
- assertEquals("2000-01-01", res.at("/collection/value").asText());
- assertEquals("type:date", res.at("/collection/type").asText());
- assertEquals("match:leq", res.at("/collection/match").asText());
- }
+ @Test
+ public void testContext () throws JsonProcessingException, IOException {
+ collection = "textClass=politik";
+ String contextString = "http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals(contextString, res.get("@context").asText());
+ }
+
+
+ @Test
+ public void testSimple () throws JsonProcessingException, IOException {
+ collection = "textClass=politik";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:doc", res.at("/collection/@type").asText());
+ assertEquals("textClass", res.at("/collection/key").asText());
+ assertEquals("politik", res.at("/collection/value").asText());
+ assertEquals("match:eq", res.at("/collection/match").asText());
+
+ collection = "textClass!=politik";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:doc", res.at("/collection/@type").asText());
+ assertEquals("textClass", res.at("/collection/key").asText());
+ assertEquals("politik", res.at("/collection/value").asText());
+ assertEquals("match:ne", res.at("/collection/match").asText());
+ }
+
+
+ @Test
+ public void testContains () throws JsonProcessingException, IOException {
+ collection = "title~Mannheim";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:doc", res.at("/collection/@type").asText());
+ assertEquals("title", res.at("/collection/key").asText());
+ assertEquals("Mannheim", res.at("/collection/value").asText());
+ assertEquals("match:contains", res.at("/collection/match").asText());
+
+ collection = "title~\"IDS Mannheim\"";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:doc", res.at("/collection/@type").asText());
+ assertEquals("title", res.at("/collection/key").asText());
+ assertEquals("IDS Mannheim", res.at("/collection/value").asText());
+ assertEquals("match:contains", res.at("/collection/match").asText());
+ }
+
+
+ @Test
+ public void testTwoConjuncts () throws JsonProcessingException, IOException {
+ collection = "textClass=Sport & pubDate in 2014";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:docGroup", res.at("/collection/@type").asText());
+ assertEquals("operation:and", res.at("/collection/operation").asText());
+ assertEquals("koral:doc", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("textClass", res.at("/collection/operands/0/key").asText());
+ assertEquals("Sport", res.at("/collection/operands/0/value").asText());
+ assertEquals("match:eq", res.at("/collection/operands/0/match")
+ .asText());
+ assertEquals("koral:doc", res.at("/collection/operands/1/@type")
+ .asText());
+ assertEquals("pubDate", res.at("/collection/operands/1/key").asText());
+ assertEquals("2014", res.at("/collection/operands/1/value").asText());
+ assertEquals("type:date", res.at("/collection/operands/1/type")
+ .asText());
+ assertEquals("match:eq", res.at("/collection/operands/1/match")
+ .asText());
+
+ collection = "textClass=Sport & pubDate=2014";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:docGroup", res.at("/collection/@type").asText());
+ assertEquals("operation:and", res.at("/collection/operation").asText());
+ assertEquals("koral:doc", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("textClass", res.at("/collection/operands/0/key").asText());
+ assertEquals("Sport", res.at("/collection/operands/0/value").asText());
+ assertEquals("match:eq", res.at("/collection/operands/0/match")
+ .asText());
+ assertEquals("koral:doc", res.at("/collection/operands/1/@type")
+ .asText());
+ assertEquals("pubDate", res.at("/collection/operands/1/key").asText());
+ assertEquals("2014", res.at("/collection/operands/1/value").asText());
+ assertEquals(true, res.at("/collection/operands/1/type")
+ .isMissingNode());
+ assertEquals("match:eq", res.at("/collection/operands/1/match")
+ .asText());
+ assertTrue(res
+ .at("/warnings/0/0")
+ .asText()
+ .startsWith(
+ "The collection query contains a value that looks like a date"));
+ }
+
+
+ @Test
+ public void testThreeConjuncts () throws JsonProcessingException,
+ IOException {
+ collection = "textClass=Sport & pubDate in 2014 & corpusId=WPD";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:docGroup", res.at("/collection/@type").asText());
+ assertEquals("operation:and", res.at("/collection/operation").asText());
+ assertEquals("koral:doc", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("textClass", res.at("/collection/operands/0/key").asText());
+ assertEquals("Sport", res.at("/collection/operands/0/value").asText());
+ assertEquals("match:eq", res.at("/collection/operands/0/match")
+ .asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/1/@type")
+ .asText());
+ assertEquals("operation:and", res
+ .at("/collection/operands/1/operation").asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/1/operands/0/@type").asText());
+ assertEquals("pubDate", res.at("/collection/operands/1/operands/0/key")
+ .asText());
+ assertEquals("2014", res.at("/collection/operands/1/operands/0/value")
+ .asText());
+ assertEquals("type:date",
+ res.at("/collection/operands/1/operands/0/type").asText());
+ assertEquals("match:eq",
+ res.at("/collection/operands/1/operands/0/match").asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/1/operands/1/@type").asText());
+ assertEquals("corpusId", res
+ .at("/collection/operands/1/operands/1/key").asText());
+ assertEquals("WPD", res.at("/collection/operands/1/operands/1/value")
+ .asText());
+ assertEquals("match:eq",
+ res.at("/collection/operands/1/operands/1/match").asText());
+ }
+
+
+ @Test
+ public void testTwoDisjuncts () throws JsonProcessingException, IOException {
+ collection = "textClass=Sport | pubDate in 2014";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:docGroup", res.at("/collection/@type").asText());
+ assertEquals("operation:or", res.at("/collection/operation").asText());
+ assertEquals("koral:doc", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("textClass", res.at("/collection/operands/0/key").asText());
+ assertEquals("Sport", res.at("/collection/operands/0/value").asText());
+ assertEquals("match:eq", res.at("/collection/operands/0/match")
+ .asText());
+ assertEquals("koral:doc", res.at("/collection/operands/1/@type")
+ .asText());
+ assertEquals("pubDate", res.at("/collection/operands/1/key").asText());
+ assertEquals("2014", res.at("/collection/operands/1/value").asText());
+ assertEquals("type:date", res.at("/collection/operands/1/type")
+ .asText());
+ assertEquals("match:eq", res.at("/collection/operands/1/match")
+ .asText());
+ }
+
+
+ @Test
+ public void testThreeDisjuncts () throws JsonProcessingException,
+ IOException {
+ collection = "textClass=Sport | pubDate in 2014 | corpusId=WPD";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:docGroup", res.at("/collection/@type").asText());
+ assertEquals("operation:or", res.at("/collection/operation").asText());
+ assertEquals("koral:doc", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("textClass", res.at("/collection/operands/0/key").asText());
+ assertEquals("Sport", res.at("/collection/operands/0/value").asText());
+ assertEquals("match:eq", res.at("/collection/operands/0/match")
+ .asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/1/@type")
+ .asText());
+ assertEquals("operation:or", res.at("/collection/operands/1/operation")
+ .asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/1/operands/0/@type").asText());
+ assertEquals("pubDate", res.at("/collection/operands/1/operands/0/key")
+ .asText());
+ assertEquals("2014", res.at("/collection/operands/1/operands/0/value")
+ .asText());
+ assertEquals("type:date",
+ res.at("/collection/operands/1/operands/0/type").asText());
+ assertEquals("match:eq",
+ res.at("/collection/operands/1/operands/0/match").asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/1/operands/1/@type").asText());
+ assertEquals("corpusId", res
+ .at("/collection/operands/1/operands/1/key").asText());
+ assertEquals("WPD", res.at("/collection/operands/1/operands/1/value")
+ .asText());
+ assertEquals("match:eq",
+ res.at("/collection/operands/1/operands/1/match").asText());
+ }
+
+
+ @Test
+ public void testMixed () throws JsonProcessingException, IOException {
+ collection = "textClass=Sport | (pubDate in 2014 & corpusId=WPD)";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:docGroup", res.at("/collection/@type").asText());
+ assertEquals("operation:or", res.at("/collection/operation").asText());
+ assertEquals("koral:doc", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("textClass", res.at("/collection/operands/0/key").asText());
+ assertEquals("Sport", res.at("/collection/operands/0/value").asText());
+ assertEquals("match:eq", res.at("/collection/operands/0/match")
+ .asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/1/@type")
+ .asText());
+ assertEquals("operation:and", res
+ .at("/collection/operands/1/operation").asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/1/operands/0/@type").asText());
+ assertEquals("pubDate", res.at("/collection/operands/1/operands/0/key")
+ .asText());
+ assertEquals("2014", res.at("/collection/operands/1/operands/0/value")
+ .asText());
+ assertEquals("type:date",
+ res.at("/collection/operands/1/operands/0/type").asText());
+ assertEquals("match:eq",
+ res.at("/collection/operands/1/operands/0/match").asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/1/operands/1/@type").asText());
+ assertEquals("corpusId", res
+ .at("/collection/operands/1/operands/1/key").asText());
+ assertEquals("WPD", res.at("/collection/operands/1/operands/1/value")
+ .asText());
+ assertEquals("match:eq",
+ res.at("/collection/operands/1/operands/1/match").asText());
+
+ collection = "textClass=Sport | pubDate in 2014 & corpusId=WPD";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:docGroup", res.at("/collection/@type").asText());
+ assertEquals("operation:or", res.at("/collection/operation").asText());
+ assertEquals("koral:doc", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("textClass", res.at("/collection/operands/0/key").asText());
+ assertEquals("Sport", res.at("/collection/operands/0/value").asText());
+ assertEquals("match:eq", res.at("/collection/operands/0/match")
+ .asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/1/@type")
+ .asText());
+ assertEquals("operation:and", res
+ .at("/collection/operands/1/operation").asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/1/operands/0/@type").asText());
+ assertEquals("pubDate", res.at("/collection/operands/1/operands/0/key")
+ .asText());
+ assertEquals("2014", res.at("/collection/operands/1/operands/0/value")
+ .asText());
+ assertEquals("type:date",
+ res.at("/collection/operands/1/operands/0/type").asText());
+ assertEquals("match:eq",
+ res.at("/collection/operands/1/operands/0/match").asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/1/operands/1/@type").asText());
+ assertEquals("corpusId", res
+ .at("/collection/operands/1/operands/1/key").asText());
+ assertEquals("WPD", res.at("/collection/operands/1/operands/1/value")
+ .asText());
+ assertEquals("match:eq",
+ res.at("/collection/operands/1/operands/1/match").asText());
+
+ collection = "(textClass=Sport | pubDate in 2014) & corpusId=WPD";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:docGroup", res.at("/collection/@type").asText());
+ assertEquals("operation:and", res.at("/collection/operation").asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("operation:or", res.at("/collection/operands/0/operation")
+ .asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/0/operands/0/@type").asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/0/operands/1/@type").asText());
+ assertEquals("koral:doc", res.at("/collection/operands/1/@type")
+ .asText());
+
+ collection = "(textClass=Sport & pubDate in 2014) & corpusId=WPD";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:docGroup", res.at("/collection/@type").asText());
+ assertEquals("operation:and", res.at("/collection/operation").asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("operation:and", res
+ .at("/collection/operands/0/operation").asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/0/operands/0/@type").asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/0/operands/1/@type").asText());
+ assertEquals("koral:doc", res.at("/collection/operands/1/@type")
+ .asText());
+
+ collection = "(textClass=Sport & textClass=ausland) | (corpusID=WPD & author=White)";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:docGroup", res.at("/collection/@type").asText());
+ assertEquals("operation:or", res.at("/collection/operation").asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("operation:and", res
+ .at("/collection/operands/0/operation").asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/1/@type")
+ .asText());
+ assertEquals("operation:and", res
+ .at("/collection/operands/1/operation").asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/0/operands/0/@type").asText());
+ assertEquals("Sport", res.at("/collection/operands/0/operands/0/value")
+ .asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/0/operands/1/@type").asText());
+ assertEquals("ausland",
+ res.at("/collection/operands/0/operands/1/value").asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/1/operands/0/@type").asText());
+ assertEquals("WPD", res.at("/collection/operands/1/operands/0/value")
+ .asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/1/operands/1/@type").asText());
+ assertEquals("White", res.at("/collection/operands/1/operands/1/value")
+ .asText());
+
+ collection = "(textClass=Sport & textClass=ausland) | (corpusID=WPD & author=White & pubDate in 2000)";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:docGroup", res.at("/collection/@type").asText());
+ assertEquals("operation:or", res.at("/collection/operation").asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/0/@type")
+ .asText());
+ assertEquals("operation:and", res
+ .at("/collection/operands/0/operation").asText());
+ assertEquals("koral:docGroup", res.at("/collection/operands/1/@type")
+ .asText());
+ assertEquals("operation:and", res
+ .at("/collection/operands/1/operation").asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/0/operands/0/@type").asText());
+ assertEquals("Sport", res.at("/collection/operands/0/operands/0/value")
+ .asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/0/operands/1/@type").asText());
+ assertEquals("ausland",
+ res.at("/collection/operands/0/operands/1/value").asText());
+ assertEquals("koral:doc",
+ res.at("/collection/operands/1/operands/0/@type").asText());
+ assertEquals("WPD", res.at("/collection/operands/1/operands/0/value")
+ .asText());
+ assertEquals("koral:docGroup",
+ res.at("/collection/operands/1/operands/1/@type").asText());
+ assertEquals("operation:and",
+ res.at("/collection/operands/1/operands/1/operation").asText());
+ assertEquals("White",
+ res.at("/collection/operands/1/operands/1/operands/0/value")
+ .asText());
+ assertEquals("2000",
+ res.at("/collection/operands/1/operands/1/operands/1/value")
+ .asText());
+ }
+
+
+ @Test
+ public void testDateYear () throws JsonProcessingException, IOException {
+ collection = "pubDate in 2000";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:doc", res.at("/collection/@type").asText());
+ assertEquals("pubDate", res.at("/collection/key").asText());
+ assertEquals("2000", res.at("/collection/value").asText());
+ assertEquals("type:date", res.at("/collection/type").asText());
+ assertEquals("match:eq", res.at("/collection/match").asText());
+
+ collection = "pubDate = 2000";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:doc", res.at("/collection/@type").asText());
+ assertEquals("pubDate", res.at("/collection/key").asText());
+ assertEquals("2000", res.at("/collection/value").asText());
+ assertEquals(true, res.at("/collection/type").isMissingNode());
+ assertEquals("match:eq", res.at("/collection/match").asText());
+
+ collection = "pubDate since 2000";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:doc", res.at("/collection/@type").asText());
+ assertEquals("pubDate", res.at("/collection/key").asText());
+ assertEquals("2000", res.at("/collection/value").asText());
+ assertEquals("type:date", res.at("/collection/type").asText());
+ assertEquals("match:geq", res.at("/collection/match").asText());
+
+ collection = "pubDate until 2000";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:doc", res.at("/collection/@type").asText());
+ assertEquals("pubDate", res.at("/collection/key").asText());
+ assertEquals("2000", res.at("/collection/value").asText());
+ assertEquals("type:date", res.at("/collection/type").asText());
+ assertEquals("match:leq", res.at("/collection/match").asText());
+ }
+
+
+ @Test
+ public void testDateMonthDay () throws JsonProcessingException, IOException {
+ collection = "pubDate in 2000-02";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:doc", res.at("/collection/@type").asText());
+ assertEquals("pubDate", res.at("/collection/key").asText());
+ assertEquals("2000-02", res.at("/collection/value").asText());
+ assertEquals("type:date", res.at("/collection/type").asText());
+ assertEquals("match:eq", res.at("/collection/match").asText());
+
+ collection = "pubDate = 2000-12";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:doc", res.at("/collection/@type").asText());
+ assertEquals("pubDate", res.at("/collection/key").asText());
+ assertEquals("2000-12", res.at("/collection/value").asText());
+ assertEquals(true, res.at("/collection/type").isMissingNode());
+ assertEquals("match:eq", res.at("/collection/match").asText());
+
+ collection = "pubDate since 2000-02-01";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:doc", res.at("/collection/@type").asText());
+ assertEquals("pubDate", res.at("/collection/key").asText());
+ assertEquals("2000-02-01", res.at("/collection/value").asText());
+ assertEquals("type:date", res.at("/collection/type").asText());
+ assertEquals("match:geq", res.at("/collection/match").asText());
+
+ collection = "pubDate until 2000-01-01";
+ qs.setQuery(query, ql);
+ qs.setCollection(collection);
+ res = mapper.readTree(qs.toJSON());
+ assertEquals("koral:doc", res.at("/collection/@type").asText());
+ assertEquals("pubDate", res.at("/collection/key").asText());
+ assertEquals("2000-01-01", res.at("/collection/value").asText());
+ assertEquals("type:date", res.at("/collection/type").asText());
+ assertEquals("match:leq", res.at("/collection/match").asText());
+ }
}
-
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessorTest.java
index a21ff8c..fa3adc8 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/Cosmas2QueryProcessorTest.java
@@ -1,4 +1,5 @@
package de.ids_mannheim.korap.query.serialize;
+
import static org.junit.Assert.*;
import java.io.IOException;
@@ -14,7 +15,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;
/**
- * Tests for JSON-LD serialization of Cosmas II queries.
+ * Tests for JSON-LD serialization of Cosmas II queries.
+ *
* @author Joachim Bingel (bingel@ids-mannheim.de)
* @version 1.0
*/
@@ -28,8 +30,9 @@
ObjectMapper mapper = new ObjectMapper();
JsonNode res;
+
@Test
- public void testContext() throws JsonProcessingException, IOException {
+ public void testContext () throws JsonProcessingException, IOException {
String contextString = "http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld";
query = "foo";
qs.setQuery(query, "cosmas2");
@@ -39,1129 +42,1783 @@
@Test
- public void testSingleToken() throws JsonProcessingException, IOException {
+ public void testSingleToken () throws JsonProcessingException, IOException {
query = "der";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("der", res.at("/query/wrap/key").asText());
- assertEquals("orth", res.at("/query/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("der", res.at("/query/wrap/key").asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
query = "&Mann";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("Mann", res.at("/query/wrap/key").asText());
- assertEquals("lemma", res.at("/query/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("Mann", res.at("/query/wrap/key").asText());
+ assertEquals("lemma", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
}
@Test
- public void testWildcardToken() throws JsonProcessingException, IOException {
+ public void testWildcardToken () throws JsonProcessingException,
+ IOException {
query = "*der";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("type:wildcard", res.at("/query/wrap/type").asText());
- assertEquals("*der", res.at("/query/wrap/key").asText());
- assertEquals("orth", res.at("/query/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("type:wildcard", res.at("/query/wrap/type").asText());
+ assertEquals("*der", res.at("/query/wrap/key").asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
query = "*de*?r";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("*de*?r", res.at("/query/wrap/key").asText());
+ assertEquals("*de*?r", res.at("/query/wrap/key").asText());
}
+
+
//
@Test
- public void testCaseSensitivityFlag() throws JsonProcessingException, IOException {
+ public void testCaseSensitivityFlag () throws JsonProcessingException,
+ IOException {
query = "$deutscher";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("deutscher", res.at("/query/wrap/key").asText());
- assertEquals("flags:caseInsensitive", res.at("/query/wrap/flags/0").asText());
- assertEquals("orth", res.at("/query/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("deutscher", res.at("/query/wrap/key").asText());
+ assertEquals("flags:caseInsensitive", res.at("/query/wrap/flags/0")
+ .asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
query = "$deutscher Bundestag";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:term", res.at("/query/operands/0/wrap/@type").asText());
- assertEquals("deutscher", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("flags:caseInsensitive", res.at("/query/operands/0/wrap/flags/0").asText());
- assertEquals("orth", res.at("/query/operands/0/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/operands/0/wrap/match").asText());
- assertEquals("Bundestag", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("koral:term", res.at("/query/operands/0/wrap/@type")
+ .asText());
+ assertEquals("deutscher", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("flags:caseInsensitive",
+ res.at("/query/operands/0/wrap/flags/0").asText());
+ assertEquals("orth", res.at("/query/operands/0/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/operands/0/wrap/match")
+ .asText());
+ assertEquals("Bundestag", res.at("/query/operands/1/wrap/key").asText());
}
+
@Test
- public void testMORPH() throws JsonProcessingException, IOException {
+ public void testMORPH () throws JsonProcessingException, IOException {
query = "MORPH(p=V)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("V", res.at("/query/wrap/key").asText());
- assertEquals("p", res.at("/query/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("V", res.at("/query/wrap/key").asText());
+ assertEquals("p", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
query = "MORPH(V)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("V", res.at("/query/wrap/key").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("V", res.at("/query/wrap/key").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
query = "MORPH(tt/p=V)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("V", res.at("/query/wrap/key").asText());
- assertEquals("p", res.at("/query/wrap/layer").asText());
- assertEquals("tt", res.at("/query/wrap/foundry").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("V", res.at("/query/wrap/key").asText());
+ assertEquals("p", res.at("/query/wrap/layer").asText());
+ assertEquals("tt", res.at("/query/wrap/foundry").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
query = "MORPH(tt/p=\"V.*\")";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("type:regex", res.at("/query/wrap/type").asText());
- assertEquals("V.*", res.at("/query/wrap/key").asText());
- assertEquals("p", res.at("/query/wrap/layer").asText());
- assertEquals("tt", res.at("/query/wrap/foundry").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("type:regex", res.at("/query/wrap/type").asText());
+ assertEquals("V.*", res.at("/query/wrap/key").asText());
+ assertEquals("p", res.at("/query/wrap/layer").asText());
+ assertEquals("tt", res.at("/query/wrap/foundry").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
query = "MORPH(mate/m=temp:pres)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("temp", res.at("/query/wrap/key").asText());
- assertEquals("pres", res.at("/query/wrap/value").asText());
- assertEquals("m", res.at("/query/wrap/layer").asText());
- assertEquals("mate", res.at("/query/wrap/foundry").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("temp", res.at("/query/wrap/key").asText());
+ assertEquals("pres", res.at("/query/wrap/value").asText());
+ assertEquals("m", res.at("/query/wrap/layer").asText());
+ assertEquals("mate", res.at("/query/wrap/foundry").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
query = "MORPH(tt/p=V & mate/m!=temp:pres)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:termGroup", res.at("/query/wrap/@type").asText());
- assertEquals("V", res.at("/query/wrap/operands/0/key").asText());
- assertEquals("p", res.at("/query/wrap/operands/0/layer").asText());
- assertEquals("tt", res.at("/query/wrap/operands/0/foundry").asText());
- assertEquals("match:eq", res.at("/query/wrap/operands/0/match").asText());
- assertEquals("temp", res.at("/query/wrap/operands/1/key").asText());
- assertEquals("pres", res.at("/query/wrap/operands/1/value").asText());
- assertEquals("m", res.at("/query/wrap/operands/1/layer").asText());
- assertEquals("mate", res.at("/query/wrap/operands/1/foundry").asText());
- assertEquals("match:ne", res.at("/query/wrap/operands/1/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:termGroup", res.at("/query/wrap/@type").asText());
+ assertEquals("V", res.at("/query/wrap/operands/0/key").asText());
+ assertEquals("p", res.at("/query/wrap/operands/0/layer").asText());
+ assertEquals("tt", res.at("/query/wrap/operands/0/foundry").asText());
+ assertEquals("match:eq", res.at("/query/wrap/operands/0/match")
+ .asText());
+ assertEquals("temp", res.at("/query/wrap/operands/1/key").asText());
+ assertEquals("pres", res.at("/query/wrap/operands/1/value").asText());
+ assertEquals("m", res.at("/query/wrap/operands/1/layer").asText());
+ assertEquals("mate", res.at("/query/wrap/operands/1/foundry").asText());
+ assertEquals("match:ne", res.at("/query/wrap/operands/1/match")
+ .asText());
}
+
@Test
- public void testSequence() throws JsonProcessingException, IOException {
+ public void testSequence () throws JsonProcessingException, IOException {
query = "der Mann";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
- assertEquals(true, res.at("/query/operands/2").isMissingNode());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals(true, res.at("/query/operands/2").isMissingNode());
query = "der Mann schläft";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
- assertEquals("schläft", res.at("/query/operands/2/wrap/key").asText());
- assertEquals(true, res.at("/query/operands/3").isMissingNode());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("schläft", res.at("/query/operands/2/wrap/key").asText());
+ assertEquals(true, res.at("/query/operands/3").isMissingNode());
query = "der Mann schläft lang";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
- assertEquals("schläft", res.at("/query/operands/2/wrap/key").asText());
- assertEquals("lang", res.at("/query/operands/3/wrap/key").asText());
- assertEquals(true, res.at("/query/operands/4").isMissingNode());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("schläft", res.at("/query/operands/2/wrap/key").asText());
+ assertEquals("lang", res.at("/query/operands/3/wrap/key").asText());
+ assertEquals(true, res.at("/query/operands/4").isMissingNode());
query = "der #ELEM(W)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("w", res.at("/query/operands/1/key").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
- assertEquals(true, res.at("/query/operands/2").isMissingNode());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("w", res.at("/query/operands/1/key").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals(true, res.at("/query/operands/2").isMissingNode());
query = "der #ELEM(W) Mann";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("w", res.at("/query/operands/1/key").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
- assertEquals("Mann", res.at("/query/operands/2/wrap/key").asText());
- assertEquals(true, res.at("/query/operands/3").isMissingNode());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("w", res.at("/query/operands/1/key").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("Mann", res.at("/query/operands/2/wrap/key").asText());
+ assertEquals(true, res.at("/query/operands/3").isMissingNode());
query = "der MORPH(p=ADJA) Mann";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("ADJA", res.at("/query/operands/1/wrap/key").asText());
- assertEquals("p", res.at("/query/operands/1/wrap/layer").asText());
- assertEquals("Mann", res.at("/query/operands/2/wrap/key").asText());
- assertEquals(true, res.at("/query/operands/3").isMissingNode());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("ADJA", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("p", res.at("/query/operands/1/wrap/layer").asText());
+ assertEquals("Mann", res.at("/query/operands/2/wrap/key").asText());
+ assertEquals(true, res.at("/query/operands/3").isMissingNode());
}
+
@Test
- public void testOPOR() throws JsonProcessingException, IOException {
+ public void testOPOR () throws JsonProcessingException, IOException {
query = "Sonne oder Mond";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:disjunction", res.at("/query/operation").asText());
- assertEquals("Sonne", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("Mond", res.at("/query/operands/1/wrap/key").asText());
- assertEquals(true, res.at("/query/operands/2").isMissingNode());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:disjunction", res.at("/query/operation")
+ .asText());
+ assertEquals("Sonne", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("Mond", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals(true, res.at("/query/operands/2").isMissingNode());
query = "(Sonne scheint) oder Mond";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:disjunction", res.at("/query/operation").asText());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
- assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals("scheint", res.at("/query/operands/0/operands/1/wrap/key").asText());
- assertEquals("Mond", res.at("/query/operands/1/wrap/key").asText());
- assertEquals(true, res.at("/query/operands/2").isMissingNode());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:disjunction", res.at("/query/operation")
+ .asText());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:sequence", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("scheint", res.at("/query/operands/0/operands/1/wrap/key")
+ .asText());
+ assertEquals("Mond", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals(true, res.at("/query/operands/2").isMissingNode());
query = "(Sonne scheint) oder (Mond scheint)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:disjunction", res.at("/query/operation").asText());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
- assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operands/1/operation").asText());
- assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals("scheint", res.at("/query/operands/0/operands/1/wrap/key").asText());
- assertEquals("Mond", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals("scheint", res.at("/query/operands/1/operands/1/wrap/key").asText());
- assertEquals(true, res.at("/query/operands/2").isMissingNode());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:disjunction", res.at("/query/operation")
+ .asText());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:sequence", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:sequence", res
+ .at("/query/operands/1/operation").asText());
+ assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("scheint", res.at("/query/operands/0/operands/1/wrap/key")
+ .asText());
+ assertEquals("Mond", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("scheint", res.at("/query/operands/1/operands/1/wrap/key")
+ .asText());
+ assertEquals(true, res.at("/query/operands/2").isMissingNode());
}
+
@Test
- public void testOPORAND() throws JsonProcessingException, IOException {
+ public void testOPORAND () throws JsonProcessingException, IOException {
query = "(Sonne oder Mond) und scheint";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("cosmas:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("t", res.at("/query/distances/0/key").asText());
- assertEquals(0, res.at("/query/distances/0/min").asInt());
- assertEquals(0, res.at("/query/distances/0/max").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:disjunction", res.at("/query/operands/0/operation").asText());
- assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals("Mond", res.at("/query/operands/0/operands/1/wrap/key").asText());
- assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
- assertEquals("scheint", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("t", res.at("/query/distances/0/key").asText());
+ assertEquals(0, res.at("/query/distances/0/min").asInt());
+ assertEquals(0, res.at("/query/distances/0/max").asInt());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:disjunction",
+ res.at("/query/operands/0/operation").asText());
+ assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("Mond", res.at("/query/operands/0/operands/1/wrap/key")
+ .asText());
+ assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
+ assertEquals("scheint", res.at("/query/operands/1/wrap/key").asText());
query = "scheint und (Sonne oder Mond)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("cosmas:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("t", res.at("/query/distances/0/key").asText());
- assertEquals(0, res.at("/query/distances/0/min").asInt());
- assertEquals(0, res.at("/query/distances/0/max").asInt());
- assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
- assertEquals("scheint", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:disjunction", res.at("/query/operands/1/operation").asText());
- assertEquals("Sonne", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals("Mond", res.at("/query/operands/1/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("t", res.at("/query/distances/0/key").asText());
+ assertEquals(0, res.at("/query/distances/0/min").asInt());
+ assertEquals(0, res.at("/query/distances/0/max").asInt());
+ assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+ assertEquals("scheint", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:disjunction",
+ res.at("/query/operands/1/operation").asText());
+ assertEquals("Sonne", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("Mond", res.at("/query/operands/1/operands/1/wrap/key")
+ .asText());
query = "Regen und scheint und (Sonne oder Mond)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("cosmas:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("t", res.at("/query/distances/0/key").asText());
- assertEquals(0, res.at("/query/distances/0/min").asInt());
- assertEquals(0, res.at("/query/distances/0/max").asInt());
- assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
- assertEquals("Regen", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("cosmas:distance", res.at("/query/operands/1/distances/0/@type").asText());
- assertEquals("t", res.at("/query/operands/1/distances/0/key").asText());
- assertEquals(0, res.at("/query/operands/1/distances/0/min").asInt());
- assertEquals(0, res.at("/query/operands/1/distances/0/max").asInt());
- assertEquals("scheint", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/operands/1/operands/1/@type").asText());
- assertEquals("operation:disjunction", res.at("/query/operands/1/operands/1/operation").asText());
- assertEquals("Sonne", res.at("/query/operands/1/operands/1/operands/0/wrap/key").asText());
- assertEquals("Mond", res.at("/query/operands/1/operands/1/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("t", res.at("/query/distances/0/key").asText());
+ assertEquals(0, res.at("/query/distances/0/min").asInt());
+ assertEquals(0, res.at("/query/distances/0/max").asInt());
+ assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+ assertEquals("Regen", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("cosmas:distance",
+ res.at("/query/operands/1/distances/0/@type").asText());
+ assertEquals("t", res.at("/query/operands/1/distances/0/key").asText());
+ assertEquals(0, res.at("/query/operands/1/distances/0/min").asInt());
+ assertEquals(0, res.at("/query/operands/1/distances/0/max").asInt());
+ assertEquals("scheint", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("koral:group", res
+ .at("/query/operands/1/operands/1/@type").asText());
+ assertEquals("operation:disjunction",
+ res.at("/query/operands/1/operands/1/operation").asText());
+ assertEquals("Sonne",
+ res.at("/query/operands/1/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("Mond",
+ res.at("/query/operands/1/operands/1/operands/1/wrap/key")
+ .asText());
}
+
@Test
- public void testOPNOT() throws JsonProcessingException, IOException {
+ public void testOPNOT () throws JsonProcessingException, IOException {
query = "Sonne nicht Mond";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("cosmas:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("t", res.at("/query/distances/0/key").asText());
- assertEquals(0, res.at("/query/distances/0/min").asInt());
- assertEquals(0, res.at("/query/distances/0/max").asInt());
- assertEquals(true, res.at("/query/distances/0/exclude").asBoolean());
- assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
- assertEquals("Sonne", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("Mond", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("t", res.at("/query/distances/0/key").asText());
+ assertEquals(0, res.at("/query/distances/0/min").asInt());
+ assertEquals(0, res.at("/query/distances/0/max").asInt());
+ assertEquals(true, res.at("/query/distances/0/exclude").asBoolean());
+ assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+ assertEquals("Sonne", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("Mond", res.at("/query/operands/1/wrap/key").asText());
query = "Sonne nicht Mond nicht Sterne";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("cosmas:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("t", res.at("/query/distances/0/key").asText());
- assertEquals(0, res.at("/query/distances/0/min").asInt());
- assertEquals(0, res.at("/query/distances/0/max").asInt());
- assertEquals(true, res.at("/query/distances/0/exclude").asBoolean());
- assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
- assertEquals("Sonne", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operands/1/operation").asText());
- assertEquals("cosmas:distance", res.at("/query/operands/1/distances/0/@type").asText());
- assertEquals("t", res.at("/query/operands/1/distances/0/key").asText());
- assertEquals(0, res.at("/query/operands/1/distances/0/min").asInt());
- assertEquals(0, res.at("/query/operands/1/distances/0/max").asInt());
- assertEquals(true, res.at("/query/operands/1/distances/0/exclude").asBoolean());
- assertEquals("Mond", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals("Sterne", res.at("/query/operands/1/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("t", res.at("/query/distances/0/key").asText());
+ assertEquals(0, res.at("/query/distances/0/min").asInt());
+ assertEquals(0, res.at("/query/distances/0/max").asInt());
+ assertEquals(true, res.at("/query/distances/0/exclude").asBoolean());
+ assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+ assertEquals("Sonne", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:sequence", res
+ .at("/query/operands/1/operation").asText());
+ assertEquals("cosmas:distance",
+ res.at("/query/operands/1/distances/0/@type").asText());
+ assertEquals("t", res.at("/query/operands/1/distances/0/key").asText());
+ assertEquals(0, res.at("/query/operands/1/distances/0/min").asInt());
+ assertEquals(0, res.at("/query/operands/1/distances/0/max").asInt());
+ assertEquals(true, res.at("/query/operands/1/distances/0/exclude")
+ .asBoolean());
+ assertEquals("Mond", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("Sterne", res.at("/query/operands/1/operands/1/wrap/key")
+ .asText());
query = "(Sonne nicht Mond) nicht Sterne";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("cosmas:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("t", res.at("/query/distances/0/key").asText());
- assertEquals(0, res.at("/query/distances/0/min").asInt());
- assertEquals(0, res.at("/query/distances/0/max").asInt());
- assertEquals(true, res.at("/query/distances/0/exclude").asBoolean());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
- assertEquals("cosmas:distance", res.at("/query/operands/0/distances/0/@type").asText());
- assertEquals("t", res.at("/query/operands/0/distances/0/key").asText());
- assertEquals(0, res.at("/query/operands/0/distances/0/min").asInt());
- assertEquals(0, res.at("/query/operands/0/distances/0/max").asInt());
- assertEquals(true, res.at("/query/operands/0/distances/0/exclude").asBoolean());
- assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals("Mond", res.at("/query/operands/0/operands/1/wrap/key").asText());
- assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
- assertEquals("Sterne", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("t", res.at("/query/distances/0/key").asText());
+ assertEquals(0, res.at("/query/distances/0/min").asInt());
+ assertEquals(0, res.at("/query/distances/0/max").asInt());
+ assertEquals(true, res.at("/query/distances/0/exclude").asBoolean());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:sequence", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("cosmas:distance",
+ res.at("/query/operands/0/distances/0/@type").asText());
+ assertEquals("t", res.at("/query/operands/0/distances/0/key").asText());
+ assertEquals(0, res.at("/query/operands/0/distances/0/min").asInt());
+ assertEquals(0, res.at("/query/operands/0/distances/0/max").asInt());
+ assertEquals(true, res.at("/query/operands/0/distances/0/exclude")
+ .asBoolean());
+ assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("Mond", res.at("/query/operands/0/operands/1/wrap/key")
+ .asText());
+ assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
+ assertEquals("Sterne", res.at("/query/operands/1/wrap/key").asText());
}
+
@Test
- public void testOPPROX() throws JsonProcessingException, IOException {
+ public void testOPPROX () throws JsonProcessingException, IOException {
query = "Sonne /+w1:4 Mond";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("w", res.at("/query/distances/0/key").asText());
- assertEquals(1, res.at("/query/distances/0/boundary/min").asInt());
- assertEquals(4, res.at("/query/distances/0/boundary/max").asInt());
- assertEquals(true, res.at("/query/inOrder").asBoolean());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/classOut").asInt());
- assertEquals(129, res.at("/query/operands/1/classOut").asInt());
- assertEquals("koral:token", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals("Mond", res.at("/query/operands/1/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("w", res.at("/query/distances/0/key").asText());
+ assertEquals(1, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(4, res.at("/query/distances/0/boundary/max").asInt());
+ assertEquals(true, res.at("/query/inOrder").asBoolean());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:class", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/0/classOut").asInt());
+ assertEquals(129, res.at("/query/operands/1/classOut").asInt());
+ assertEquals("koral:token", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("Mond", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
query = "Sonne /+w1:4,s0,p1:3 Mond";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("w", res.at("/query/distances/0/key").asText());
- assertEquals(1, res.at("/query/distances/0/boundary/min").asInt());
- assertEquals(4, res.at("/query/distances/0/boundary/max").asInt());
- assertEquals("s", res.at("/query/distances/1/key").asText());
- assertEquals(0, res.at("/query/distances/1/boundary/min").asInt());
- assertEquals("p", res.at("/query/distances/2/key").asText());
- assertEquals(1, res.at("/query/distances/2/boundary/min").asInt());
- assertEquals(3, res.at("/query/distances/2/boundary/max").asInt());
- assertEquals(true, res.at("/query/inOrder").asBoolean());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/classOut").asInt());
- assertEquals(129, res.at("/query/operands/1/classOut").asInt());
- assertEquals("koral:token", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals("Mond", res.at("/query/operands/1/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("w", res.at("/query/distances/0/key").asText());
+ assertEquals(1, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(4, res.at("/query/distances/0/boundary/max").asInt());
+ assertEquals("s", res.at("/query/distances/1/key").asText());
+ assertEquals(0, res.at("/query/distances/1/boundary/min").asInt());
+ assertEquals("p", res.at("/query/distances/2/key").asText());
+ assertEquals(1, res.at("/query/distances/2/boundary/min").asInt());
+ assertEquals(3, res.at("/query/distances/2/boundary/max").asInt());
+ assertEquals(true, res.at("/query/inOrder").asBoolean());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:class", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/0/classOut").asInt());
+ assertEquals(129, res.at("/query/operands/1/classOut").asInt());
+ assertEquals("koral:token", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("Mond", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
query = "Sonne /+w4 Mond";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("w", res.at("/query/distances/0/key").asText());
- assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
- assertEquals(4, res.at("/query/distances/0/boundary/max").asInt());
+ assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("w", res.at("/query/distances/0/key").asText());
+ assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(4, res.at("/query/distances/0/boundary/max").asInt());
query = "Sonne /-w4 Mond";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("w", res.at("/query/distances/0/key").asText());
- assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
- assertEquals(4, res.at("/query/distances/0/boundary/max").asInt());
- assertEquals("Mond", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals("Sonne", res.at("/query/operands/1/operands/0/wrap/key").asText());
+ assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("w", res.at("/query/distances/0/key").asText());
+ assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(4, res.at("/query/distances/0/boundary/max").asInt());
+ assertEquals("Mond", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("Sonne", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
query = "Sonne /w4 Mond";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("w", res.at("/query/distances/0/key").asText());
- assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
- assertEquals(4, res.at("/query/distances/0/boundary/max").asInt());
- assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals("Mond", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals(false, res.at("/query/inOrder").asBoolean());
+ assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("w", res.at("/query/distances/0/key").asText());
+ assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(4, res.at("/query/distances/0/boundary/max").asInt());
+ assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("Mond", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals(false, res.at("/query/inOrder").asBoolean());
}
+
@Test
- public void testOPPROXNested() throws JsonProcessingException, IOException {
+ public void testOPPROXNested () throws JsonProcessingException, IOException {
query = "Sonne /+w1:4 Mond /+w1:7 Sterne";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("w", res.at("/query/distances/0/key").asText());
- assertEquals(1, res.at("/query/distances/0/boundary/min").asInt());
- assertEquals(4, res.at("/query/distances/0/boundary/max").asInt());
- assertEquals(true, res.at("/query/inOrder").asBoolean());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/classOut").asInt());
- assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals(129, res.at("/query/operands/1/classOut").asInt());
- assertEquals("operation:sequence", res.at("/query/operands/1/operands/0/operation").asText());
- assertEquals("w", res.at("/query/operands/1/operands/0/distances/0/key").asText());
- assertEquals(1, res.at("/query/operands/1/operands/0/distances/0/boundary/min").asInt());
- assertEquals(7, res.at("/query/operands/1/operands/0/distances/0/boundary/max").asInt());
- assertEquals(130, res.at("/query/operands/1/operands/0/operands/0/classOut").asInt());
- assertEquals("Mond", res.at("/query/operands/1/operands/0/operands/0/operands/0/wrap/key").asText());
- assertEquals(130, res.at("/query/operands/1/operands/0/operands/1/classOut").asInt());
- assertEquals("Sterne", res.at("/query/operands/1/operands/0/operands/1/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("w", res.at("/query/distances/0/key").asText());
+ assertEquals(1, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(4, res.at("/query/distances/0/boundary/max").asInt());
+ assertEquals(true, res.at("/query/inOrder").asBoolean());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:class", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/0/classOut").asInt());
+ assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals(129, res.at("/query/operands/1/classOut").asInt());
+ assertEquals("operation:sequence",
+ res.at("/query/operands/1/operands/0/operation").asText());
+ assertEquals("w", res
+ .at("/query/operands/1/operands/0/distances/0/key").asText());
+ assertEquals(1,
+ res.at("/query/operands/1/operands/0/distances/0/boundary/min")
+ .asInt());
+ assertEquals(7,
+ res.at("/query/operands/1/operands/0/distances/0/boundary/max")
+ .asInt());
+ assertEquals(130,
+ res.at("/query/operands/1/operands/0/operands/0/classOut")
+ .asInt());
+ assertEquals(
+ "Mond",
+ res.at("/query/operands/1/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals(130,
+ res.at("/query/operands/1/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "Sterne",
+ res.at("/query/operands/1/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
query = "Sonne /+w1:4 Mond /-w1:7 Sterne";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals("Sterne", res.at("/query/operands/1/operands/0/operands/0/operands/0/wrap/key").asText());
- assertEquals("Mond", res.at("/query/operands/1/operands/0/operands/1/operands/0/wrap/key").asText());
+ assertEquals("Sonne", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals(
+ "Sterne",
+ res.at("/query/operands/1/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals(
+ "Mond",
+ res.at("/query/operands/1/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
query = "Sonne /-w4 Mond /+w2 Sterne";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("w", res.at("/query/distances/0/key").asText());
- assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
- assertEquals(4, res.at("/query/distances/0/boundary/max").asInt());
- assertEquals(true, res.at("/query/inOrder").asBoolean());
- assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/1/operation").asText());
- assertEquals(129, res.at("/query/operands/1/classOut").asInt());
- assertEquals("Sonne", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals(129, res.at("/query/operands/0/classOut").asInt());
- assertEquals("operation:sequence", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("w", res.at("/query/operands/0/operands/0/distances/0/key").asText());
- assertEquals(0, res.at("/query/operands/0/operands/0/distances/0/boundary/min").asInt());
- assertEquals(2, res.at("/query/operands/0/operands/0/distances/0/boundary/max").asInt());
- assertEquals(130, res.at("/query/operands/0/operands/0/operands/0/classOut").asInt());
- assertEquals("Mond", res.at("/query/operands/0/operands/0/operands/0/operands/0/wrap/key").asText());
- assertEquals(130, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
- assertEquals("Sterne", res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("w", res.at("/query/distances/0/key").asText());
+ assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(4, res.at("/query/distances/0/boundary/max").asInt());
+ assertEquals(true, res.at("/query/inOrder").asBoolean());
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:class", res.at("/query/operands/1/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/1/classOut").asInt());
+ assertEquals("Sonne", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals(129, res.at("/query/operands/0/classOut").asInt());
+ assertEquals("operation:sequence",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("w", res
+ .at("/query/operands/0/operands/0/distances/0/key").asText());
+ assertEquals(0,
+ res.at("/query/operands/0/operands/0/distances/0/boundary/min")
+ .asInt());
+ assertEquals(2,
+ res.at("/query/operands/0/operands/0/distances/0/boundary/max")
+ .asInt());
+ assertEquals(130,
+ res.at("/query/operands/0/operands/0/operands/0/classOut")
+ .asInt());
+ assertEquals(
+ "Mond",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals(130,
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "Sterne",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
}
+
@Test
- public void testOPIN() throws JsonProcessingException, IOException {
+ public void testOPIN () throws JsonProcessingException, IOException {
query = "wegen #IN <s>";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals(130, res.at("/query/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operation").asText());
- assertEquals("classRefCheck:includes", res.at("/query/operands/0/classRefCheck/0").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals(true, res.at("/query/operands/0/operands/0/frames/0").isMissingNode());
- assertEquals(129, res.at("/query/operands/0/classIn/0").asInt());
- assertEquals(130, res.at("/query/operands/0/classIn/1").asInt());
- assertEquals(131, res.at("/query/operands/0/classOut").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/operands/0/classOut").asInt());
- assertEquals("koral:span", res.at("/query/operands/0/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/operands/0/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
- assertEquals(130, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
- assertEquals("koral:token", res.at("/query/operands/0/operands/0/operands/1/operands/0/@type").asText());
- assertEquals("wegen", res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals(130, res.at("/query/classRef/0").asInt());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:class", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals("classRefCheck:includes",
+ res.at("/query/operands/0/classRefCheck/0").asText());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:position",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals(true, res.at("/query/operands/0/operands/0/frames/0")
+ .isMissingNode());
+ assertEquals(129, res.at("/query/operands/0/classIn/0").asInt());
+ assertEquals(130, res.at("/query/operands/0/classIn/1").asInt());
+ assertEquals(131, res.at("/query/operands/0/classOut").asInt());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/0/operands/0/classOut")
+ .asInt());
+ assertEquals(
+ "koral:span",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals(
+ "s",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/key")
+ .asText());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/0/operands/1/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(130,
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "koral:token",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/@type")
+ .asText());
+ assertEquals(
+ "wegen",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
query = "wegen #IN(L) <s>";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals(130, res.at("/query/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operation").asText());
- assertEquals("frames:startsWith", res.at("/query/operands/0/frames/0").asText());
- assertEquals("frames:matches", res.at("/query/operands/0/frames/1").asText());
- assertEquals(true, res.at("/query/operands/0/frames/2").isMissingNode());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/classOut").asInt());
- assertEquals("koral:span", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
- assertEquals(130, res.at("/query/operands/0/operands/1/classOut").asInt());
- assertEquals("koral:token", res.at("/query/operands/0/operands/1/operands/0/@type").asText());
- assertEquals("wegen", res.at("/query/operands/0/operands/1/operands/0/wrap/key").asText());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals(130, res.at("/query/classRef/0").asInt());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:position", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("frames:startsWith", res.at("/query/operands/0/frames/0")
+ .asText());
+ assertEquals("frames:matches", res.at("/query/operands/0/frames/1")
+ .asText());
+ assertEquals(true, res.at("/query/operands/0/frames/2").isMissingNode());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals(129, res.at("/query/operands/0/operands/0/classOut")
+ .asInt());
+ assertEquals("koral:span",
+ res.at("/query/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/key")
+ .asText());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/1/@type").asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/1/operation").asText());
+ assertEquals(130, res.at("/query/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals("koral:token",
+ res.at("/query/operands/0/operands/1/operands/0/@type")
+ .asText());
+ assertEquals("wegen",
+ res.at("/query/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
query = "wegen #IN(F) <s>";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals(true, res.at("/query/operands/0/classRefCheck").isMissingNode());
- assertEquals("frames:matches", res.at("/query/operands/0/frames/0").asText());
- assertEquals(true, res.at("/query/operands/0/frames/1").isMissingNode());
+ assertEquals(true, res.at("/query/operands/0/classRefCheck")
+ .isMissingNode());
+ assertEquals("frames:matches", res.at("/query/operands/0/frames/0")
+ .asText());
+ assertEquals(true, res.at("/query/operands/0/frames/1").isMissingNode());
query = "wegen #IN(FI) <s>";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("classRefCheck:unequals", res.at("/query/operands/0/classRefCheck/0").asText());
- assertEquals("frames:matches", res.at("/query/operands/0/operands/0/frames/0").asText());
- assertEquals(true, res.at("/query/operands/0/operands/0/frames/1").isMissingNode());
+ assertEquals("classRefCheck:unequals",
+ res.at("/query/operands/0/classRefCheck/0").asText());
+ assertEquals("frames:matches",
+ res.at("/query/operands/0/operands/0/frames/0").asText());
+ assertEquals(true, res.at("/query/operands/0/operands/0/frames/1")
+ .isMissingNode());
query = "wegen #IN(FE) <s>";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("classRefCheck:equals", res.at("/query/operands/0/classRefCheck/0").asText());
- assertEquals("frames:matches", res.at("/query/operands/0/operands/0/frames/0").asText());
- assertEquals(true, res.at("/query/operands/0/operands/0/frames/1").isMissingNode());
+ assertEquals("classRefCheck:equals",
+ res.at("/query/operands/0/classRefCheck/0").asText());
+ assertEquals("frames:matches",
+ res.at("/query/operands/0/operands/0/frames/0").asText());
+ assertEquals(true, res.at("/query/operands/0/operands/0/frames/1")
+ .isMissingNode());
query = "wegen #IN(%, L) <s>";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("frames:startsWith", res.at("/query/operands/0/frames/0").asText());
- assertEquals("frames:matches", res.at("/query/operands/0/frames/1").asText());
+ assertEquals("frames:startsWith", res.at("/query/operands/0/frames/0")
+ .asText());
+ assertEquals("frames:matches", res.at("/query/operands/0/frames/1")
+ .asText());
// assertEquals(true, res.at("/query/operands/0/operands/0/exclude").isMissingNode());
query = "wegen #IN(FE,%,MIN) <s>";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("classRefCheck:equals", res.at("/query/operands/0/classRefCheck/0").asText());
- assertEquals("frames:matches", res.at("/query/operands/0/operands/0/frames/0").asText());
+ assertEquals("classRefCheck:equals",
+ res.at("/query/operands/0/classRefCheck/0").asText());
+ assertEquals("frames:matches",
+ res.at("/query/operands/0/operands/0/frames/0").asText());
// assertEquals(true, res.at("/query/operands/0/operands/0/exclude").isMissingNode());
query = "wegen #IN(FE,ALL,%,MIN) <s>";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("operation:class", res.at("/query/operation").asText());
- assertEquals("classRefOp:delete", res.at("/query/classRefOp").asText());
- assertEquals(131, res.at("/query/classIn/0").asInt());
- assertEquals("classRefCheck:equals", res.at("/query/operands/0/classRefCheck/0").asText());
- assertEquals("frames:matches", res.at("/query/operands/0/operands/0/frames/0").asText());
- assertEquals(true, res.at("/query/operands/0/operands/0/exclude").asBoolean());
+ assertEquals("operation:class", res.at("/query/operation").asText());
+ assertEquals("classRefOp:delete", res.at("/query/classRefOp").asText());
+ assertEquals(131, res.at("/query/classIn/0").asInt());
+ assertEquals("classRefCheck:equals",
+ res.at("/query/operands/0/classRefCheck/0").asText());
+ assertEquals("frames:matches",
+ res.at("/query/operands/0/operands/0/frames/0").asText());
+ assertEquals(true, res.at("/query/operands/0/operands/0/exclude")
+ .asBoolean());
query = "wegen #IN(FE,ALL,%,MAX) <s>";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("operation:merge", res.at("/query/operation").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operation").asText());
- assertEquals("classRefOp:delete", res.at("/query/operands/0/classRefOp").asText());
- assertEquals(131, res.at("/query/operands/0/classIn/0").asInt());
- assertEquals("classRefCheck:equals", res.at("/query/operands/0/operands/0/classRefCheck/0").asText());
- assertEquals("frames:matches", res.at("/query/operands/0/operands/0/operands/0/frames/0").asText());
- assertEquals(true, res.at("/query/operands/0/operands/0/operands/0/exclude").asBoolean());
+ assertEquals("operation:merge", res.at("/query/operation").asText());
+ assertEquals("operation:class", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals("classRefOp:delete", res
+ .at("/query/operands/0/classRefOp").asText());
+ assertEquals(131, res.at("/query/operands/0/classIn/0").asInt());
+ assertEquals("classRefCheck:equals",
+ res.at("/query/operands/0/operands/0/classRefCheck/0").asText());
+ assertEquals("frames:matches",
+ res.at("/query/operands/0/operands/0/operands/0/frames/0")
+ .asText());
+ assertEquals(true,
+ res.at("/query/operands/0/operands/0/operands/0/exclude")
+ .asBoolean());
}
+
@Test
- public void testOPOV() throws JsonProcessingException, IOException {
+ public void testOPOV () throws JsonProcessingException, IOException {
query = "wegen #OV <s>";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals(130, res.at("/query/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operation").asText());
- assertEquals("classRefCheck:intersects", res.at("/query/operands/0/classRefCheck/0").asText());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals(130, res.at("/query/classRef/0").asInt());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:class", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals("classRefCheck:intersects",
+ res.at("/query/operands/0/classRefCheck/0").asText());
// assertEquals("classRefOp:merge", res.at("/query/operands/0/classRefOp").asText());
- assertEquals(131, res.at("/query/operands/0/classOut").asInt());
- assertEquals(129, res.at("/query/operands/0/classIn/0").asInt());
- assertEquals(130, res.at("/query/operands/0/classIn/1").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals(true, res.at("/query/operands/0/operands/0/frames/0").isMissingNode());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/operands/0/classOut").asInt());
- assertEquals("koral:span", res.at("/query/operands/0/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/operands/0/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
- assertEquals(130, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
- assertEquals("koral:token", res.at("/query/operands/0/operands/0/operands/1/operands/0/@type").asText());
- assertEquals("wegen", res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
+ assertEquals(131, res.at("/query/operands/0/classOut").asInt());
+ assertEquals(129, res.at("/query/operands/0/classIn/0").asInt());
+ assertEquals(130, res.at("/query/operands/0/classIn/1").asInt());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:position",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals(true, res.at("/query/operands/0/operands/0/frames/0")
+ .isMissingNode());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/0/operands/0/classOut")
+ .asInt());
+ assertEquals(
+ "koral:span",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals(
+ "s",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/key")
+ .asText());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/0/operands/1/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(130,
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "koral:token",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/@type")
+ .asText());
+ assertEquals(
+ "wegen",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
query = "wegen #OV(L) <s>";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("classRefCheck:intersects", res.at("/query/operands/0/classRefCheck/0").asText());
- assertEquals("frames:startsWith", res.at("/query/operands/0/operands/0/frames/0").asText());
- assertEquals("frames:overlapsLeft", res.at("/query/operands/0/operands/0/frames/1").asText());
- assertEquals("frames:matches", res.at("/query/operands/0/operands/0/frames/2").asText());
+ assertEquals("classRefCheck:intersects",
+ res.at("/query/operands/0/classRefCheck/0").asText());
+ assertEquals("frames:startsWith",
+ res.at("/query/operands/0/operands/0/frames/0").asText());
+ assertEquals("frames:overlapsLeft",
+ res.at("/query/operands/0/operands/0/frames/1").asText());
+ assertEquals("frames:matches",
+ res.at("/query/operands/0/operands/0/frames/2").asText());
query = "wegen #OV(F) <s>";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("classRefCheck:intersects", res.at("/query/operands/0/classRefCheck/0").asText());
- assertEquals("frames:matches", res.at("/query/operands/0/operands/0/frames/0").asText());
- assertEquals(true, res.at("/query/operands/0/operands/0/frames/1").isMissingNode());
+ assertEquals("classRefCheck:intersects",
+ res.at("/query/operands/0/classRefCheck/0").asText());
+ assertEquals("frames:matches",
+ res.at("/query/operands/0/operands/0/frames/0").asText());
+ assertEquals(true, res.at("/query/operands/0/operands/0/frames/1")
+ .isMissingNode());
query = "wegen #OV(FI) <s>";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("classRefCheck:unequals", res.at("/query/operands/0/classRefCheck/0").asText());
- assertEquals("frames:matches", res.at("/query/operands/0/operands/0/frames/0").asText());
+ assertEquals("classRefCheck:unequals",
+ res.at("/query/operands/0/classRefCheck/0").asText());
+ assertEquals("frames:matches",
+ res.at("/query/operands/0/operands/0/frames/0").asText());
query = "wegen #OV(FE) <s>";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("classRefCheck:equals", res.at("/query/operands/0/classRefCheck/0").asText());
- assertEquals("frames:matches", res.at("/query/operands/0/operands/0/frames/0").asText());
+ assertEquals("classRefCheck:equals",
+ res.at("/query/operands/0/classRefCheck/0").asText());
+ assertEquals("frames:matches",
+ res.at("/query/operands/0/operands/0/frames/0").asText());
}
@Test
- public void testBEG_END() throws JsonProcessingException, IOException {
+ public void testBEG_END () throws JsonProcessingException, IOException {
query = "#BEG(der /w3:5 Mann)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals(0, res.at("/query/spanRef/0").asInt());
- assertEquals(1, res.at("/query/spanRef/1").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
- assertEquals("koral:distance", res.at("/query/operands/0/distances/0/@type").asText());
- assertEquals("w", res.at("/query/operands/0/distances/0/key").asText());
- assertEquals(3, res.at("/query/operands/0/distances/0/boundary/min").asInt());
- assertEquals(5, res.at("/query/operands/0/distances/0/boundary/max").asInt());
- assertEquals(false, res.at("/query/operands/0/inOrder").asBoolean());
- assertEquals("koral:token", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals("Mann", res.at("/query/operands/0/operands/1/wrap/key").asText());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals(0, res.at("/query/spanRef/0").asInt());
+ assertEquals(1, res.at("/query/spanRef/1").asInt());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:sequence", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("cosmas:distance",
+ res.at("/query/operands/0/distances/0/@type").asText());
+ assertEquals("w", res.at("/query/operands/0/distances/0/key").asText());
+ assertEquals(3, res.at("/query/operands/0/distances/0/boundary/min")
+ .asInt());
+ assertEquals(5, res.at("/query/operands/0/distances/0/boundary/max")
+ .asInt());
+ assertEquals(false, res.at("/query/operands/0/inOrder").asBoolean());
+ assertEquals("koral:token", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("Mann", res.at("/query/operands/0/operands/1/wrap/key")
+ .asText());
query = "#BEG(der /w3:5 Mann) /+w10 kommt";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("w", res.at("/query/distances/0/key").asText());
- assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
- assertEquals(10, res.at("/query/distances/0/boundary/max").asInt());
- assertEquals(true, res.at("/query/inOrder").asBoolean());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/classOut").asInt());
- assertEquals("koral:reference", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals(0, res.at("/query/operands/0/operands/0/spanRef/0").asInt());
- assertEquals(1, res.at("/query/operands/0/operands/0/spanRef/1").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operands/0/operands/0/operands/0/operation").asText());
- assertEquals("koral:distance", res.at("/query/operands/0/operands/0/operands/0/distances/0/@type").asText());
- assertEquals("w", res.at("/query/operands/0/operands/0/operands/0/distances/0/key").asText());
- assertEquals(3, res.at("/query/operands/0/operands/0/operands/0/distances/0/boundary/min").asInt());
- assertEquals(5, res.at("/query/operands/0/operands/0/operands/0/distances/0/boundary/max").asInt());
- assertEquals(false, res.at("/query/operands/0/operands/0/operands/0/inOrder").asBoolean());
- assertEquals("koral:token", res.at("/query/operands/0/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("der", res.at("/query/operands/0/operands/0/operands/0/operands/0/wrap/key").asText());
- assertEquals("Mann", res.at("/query/operands/0/operands/0/operands/0/operands/1/wrap/key").asText());
- assertEquals("operation:class", res.at("/query/operands/1/operation").asText());
- assertEquals(129, res.at("/query/operands/1/classOut").asInt());
- assertEquals("koral:token", res.at("/query/operands/1/operands/0/@type").asText());
- assertEquals("kommt", res.at("/query/operands/1/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("w", res.at("/query/distances/0/key").asText());
+ assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(10, res.at("/query/distances/0/boundary/max").asInt());
+ assertEquals(true, res.at("/query/inOrder").asBoolean());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:class", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/0/classOut").asInt());
+ assertEquals("koral:reference",
+ res.at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:focus",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals(0, res.at("/query/operands/0/operands/0/spanRef/0")
+ .asInt());
+ assertEquals(1, res.at("/query/operands/0/operands/0/spanRef/1")
+ .asInt());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("operation:sequence",
+ res.at("/query/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(
+ "cosmas:distance",
+ res.at("/query/operands/0/operands/0/operands/0/distances/0/@type")
+ .asText());
+ assertEquals(
+ "w",
+ res.at("/query/operands/0/operands/0/operands/0/distances/0/key")
+ .asText());
+ assertEquals(
+ 3,
+ res.at("/query/operands/0/operands/0/operands/0/distances/0/boundary/min")
+ .asInt());
+ assertEquals(
+ 5,
+ res.at("/query/operands/0/operands/0/operands/0/distances/0/boundary/max")
+ .asInt());
+ assertEquals(false,
+ res.at("/query/operands/0/operands/0/operands/0/inOrder")
+ .asBoolean());
+ assertEquals(
+ "koral:token",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals(
+ "der",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals(
+ "Mann",
+ res.at("/query/operands/0/operands/0/operands/0/operands/1/wrap/key")
+ .asText());
+ assertEquals("operation:class", res.at("/query/operands/1/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/1/classOut").asInt());
+ assertEquals("koral:token", res
+ .at("/query/operands/1/operands/0/@type").asText());
+ assertEquals("kommt", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
query = "kommt /+w10 #BEG(der /w3:5 Mann)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("w", res.at("/query/distances/0/key").asText());
- assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
- assertEquals(10, res.at("/query/distances/0/boundary/max").asInt());
- assertEquals(true, res.at("/query/inOrder").asBoolean());
- assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/1/operation").asText());
- assertEquals(129, res.at("/query/operands/1/classOut").asInt());
- assertEquals("koral:reference", res.at("/query/operands/1/operands/0/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/1/operands/0/operation").asText());
- assertEquals(0, res.at("/query/operands/1/operands/0/spanRef/0").asInt());
- assertEquals(1, res.at("/query/operands/1/operands/0/spanRef/1").asInt());
- assertEquals("koral:group", res.at("/query/operands/1/operands/0/operands/0/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operands/1/operands/0/operands/0/operation").asText());
- assertEquals("koral:distance", res.at("/query/operands/1/operands/0/operands/0/distances/0/@type").asText());
- assertEquals("w", res.at("/query/operands/1/operands/0/operands/0/distances/0/key").asText());
- assertEquals(3, res.at("/query/operands/1/operands/0/operands/0/distances/0/boundary/min").asInt());
- assertEquals(5, res.at("/query/operands/1/operands/0/operands/0/distances/0/boundary/max").asInt());
- assertEquals(false, res.at("/query/operands/1/operands/0/operands/0/inOrder").asBoolean());
- assertEquals("koral:token", res.at("/query/operands/1/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("der", res.at("/query/operands/1/operands/0/operands/0/operands/0/wrap/key").asText());
- assertEquals("Mann", res.at("/query/operands/1/operands/0/operands/0/operands/1/wrap/key").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/classOut").asInt());
- assertEquals("koral:token", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("kommt", res.at("/query/operands/0/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("w", res.at("/query/distances/0/key").asText());
+ assertEquals(0, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(10, res.at("/query/distances/0/boundary/max").asInt());
+ assertEquals(true, res.at("/query/inOrder").asBoolean());
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:class", res.at("/query/operands/1/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/1/classOut").asInt());
+ assertEquals("koral:reference",
+ res.at("/query/operands/1/operands/0/@type").asText());
+ assertEquals("operation:focus",
+ res.at("/query/operands/1/operands/0/operation").asText());
+ assertEquals(0, res.at("/query/operands/1/operands/0/spanRef/0")
+ .asInt());
+ assertEquals(1, res.at("/query/operands/1/operands/0/spanRef/1")
+ .asInt());
+ assertEquals("koral:group",
+ res.at("/query/operands/1/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("operation:sequence",
+ res.at("/query/operands/1/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(
+ "cosmas:distance",
+ res.at("/query/operands/1/operands/0/operands/0/distances/0/@type")
+ .asText());
+ assertEquals(
+ "w",
+ res.at("/query/operands/1/operands/0/operands/0/distances/0/key")
+ .asText());
+ assertEquals(
+ 3,
+ res.at("/query/operands/1/operands/0/operands/0/distances/0/boundary/min")
+ .asInt());
+ assertEquals(
+ 5,
+ res.at("/query/operands/1/operands/0/operands/0/distances/0/boundary/max")
+ .asInt());
+ assertEquals(false,
+ res.at("/query/operands/1/operands/0/operands/0/inOrder")
+ .asBoolean());
+ assertEquals(
+ "koral:token",
+ res.at("/query/operands/1/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals(
+ "der",
+ res.at("/query/operands/1/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals(
+ "Mann",
+ res.at("/query/operands/1/operands/0/operands/0/operands/1/wrap/key")
+ .asText());
+ assertEquals("operation:class", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(129, res.at("/query/operands/0/classOut").asInt());
+ assertEquals("koral:token", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("kommt", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
query = "#END(der /w3:5 Mann)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals(-1, res.at("/query/spanRef/0").asInt());
- assertEquals(1, res.at("/query/spanRef/1").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
- assertEquals("koral:distance", res.at("/query/operands/0/distances/0/@type").asText());
- assertEquals("w", res.at("/query/operands/0/distances/0/key").asText());
- assertEquals(3, res.at("/query/operands/0/distances/0/boundary/min").asInt());
- assertEquals(5, res.at("/query/operands/0/distances/0/boundary/max").asInt());
- assertEquals(false, res.at("/query/operands/0/inOrder").asBoolean());
- assertEquals("koral:token", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals("Mann", res.at("/query/operands/0/operands/1/wrap/key").asText());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals(-1, res.at("/query/spanRef/0").asInt());
+ assertEquals(1, res.at("/query/spanRef/1").asInt());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:sequence", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("cosmas:distance",
+ res.at("/query/operands/0/distances/0/@type").asText());
+ assertEquals("w", res.at("/query/operands/0/distances/0/key").asText());
+ assertEquals(3, res.at("/query/operands/0/distances/0/boundary/min")
+ .asInt());
+ assertEquals(5, res.at("/query/operands/0/distances/0/boundary/max")
+ .asInt());
+ assertEquals(false, res.at("/query/operands/0/inOrder").asBoolean());
+ assertEquals("koral:token", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("Mann", res.at("/query/operands/0/operands/1/wrap/key")
+ .asText());
}
+
@Test
- public void testELEM() throws JsonProcessingException, IOException {
+ public void testELEM () throws JsonProcessingException, IOException {
query = "#ELEM(S)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("s", res.at("/query/key").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("s", res.at("/query/key").asText());
query = "#ELEM(W ANA=N)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("w", res.at("/query/key").asText());
- assertEquals("koral:term", res.at("/query/attr/@type").asText());
- assertEquals("N", res.at("/query/attr/key").asText());
- assertEquals("p", res.at("/query/attr/layer").asText());
- assertEquals("match:eq", res.at("/query/attr/match").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("w", res.at("/query/key").asText());
+ assertEquals("koral:term", res.at("/query/attr/@type").asText());
+ assertEquals("N", res.at("/query/attr/key").asText());
+ assertEquals("p", res.at("/query/attr/layer").asText());
+ assertEquals("match:eq", res.at("/query/attr/match").asText());
query = "#ELEM(W ANA != 'N V')";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("w", res.at("/query/key").asText());
- assertEquals("koral:termGroup", res.at("/query/attr/@type").asText());
- assertEquals("relation:and", res.at("/query/attr/relation").asText());
- assertEquals("koral:term", res.at("/query/attr/operands/0/@type").asText());
- assertEquals("N", res.at("/query/attr/operands/0/key").asText());
- assertEquals("p", res.at("/query/attr/operands/0/layer").asText());
- assertEquals("match:ne", res.at("/query/attr/operands/0/match").asText());
- assertEquals("koral:term", res.at("/query/attr/operands/1/@type").asText());
- assertEquals("V", res.at("/query/attr/operands/1/key").asText());
- assertEquals("p", res.at("/query/attr/operands/1/layer").asText());
- assertEquals("match:ne", res.at("/query/attr/operands/1/match").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("w", res.at("/query/key").asText());
+ assertEquals("koral:termGroup", res.at("/query/attr/@type").asText());
+ assertEquals("relation:and", res.at("/query/attr/relation").asText());
+ assertEquals("koral:term", res.at("/query/attr/operands/0/@type")
+ .asText());
+ assertEquals("N", res.at("/query/attr/operands/0/key").asText());
+ assertEquals("p", res.at("/query/attr/operands/0/layer").asText());
+ assertEquals("match:ne", res.at("/query/attr/operands/0/match")
+ .asText());
+ assertEquals("koral:term", res.at("/query/attr/operands/1/@type")
+ .asText());
+ assertEquals("V", res.at("/query/attr/operands/1/key").asText());
+ assertEquals("p", res.at("/query/attr/operands/1/layer").asText());
+ assertEquals("match:ne", res.at("/query/attr/operands/1/match")
+ .asText());
query = "#ELEM(W ANA != 'N A V' Genre = Sport)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("w", res.at("/query/key").asText());
- assertEquals("koral:termGroup", res.at("/query/attr/@type").asText());
- assertEquals("relation:and", res.at("/query/attr/relation").asText());
- assertEquals("koral:termGroup", res.at("/query/attr/operands/0/@type").asText());
- assertEquals("relation:and", res.at("/query/attr/operands/0/relation").asText());
- assertEquals("N", res.at("/query/attr/operands/0/operands/0/key").asText());
- assertEquals("A", res.at("/query/attr/operands/0/operands/1/key").asText());
- assertEquals("V", res.at("/query/attr/operands/0/operands/2/key").asText());
- assertEquals("Genre", res.at("/query/attr/operands/1/layer").asText());
- assertEquals("Sport", res.at("/query/attr/operands/1/key").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("w", res.at("/query/key").asText());
+ assertEquals("koral:termGroup", res.at("/query/attr/@type").asText());
+ assertEquals("relation:and", res.at("/query/attr/relation").asText());
+ assertEquals("koral:termGroup", res.at("/query/attr/operands/0/@type")
+ .asText());
+ assertEquals("relation:and", res.at("/query/attr/operands/0/relation")
+ .asText());
+ assertEquals("N", res.at("/query/attr/operands/0/operands/0/key")
+ .asText());
+ assertEquals("A", res.at("/query/attr/operands/0/operands/1/key")
+ .asText());
+ assertEquals("V", res.at("/query/attr/operands/0/operands/2/key")
+ .asText());
+ assertEquals("Genre", res.at("/query/attr/operands/1/layer").asText());
+ assertEquals("Sport", res.at("/query/attr/operands/1/key").asText());
query = "#ELEM(W ANA != 'N A V' Genre != 'Sport Politik')";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("w", res.at("/query/key").asText());
- assertEquals("koral:termGroup", res.at("/query/attr/@type").asText());
- assertEquals("relation:and", res.at("/query/attr/relation").asText());
- assertEquals("koral:termGroup", res.at("/query/attr/operands/0/@type").asText());
- assertEquals("relation:and", res.at("/query/attr/operands/0/relation").asText());
- assertEquals("koral:termGroup", res.at("/query/attr/operands/1/@type").asText());
- assertEquals("relation:and", res.at("/query/attr/operands/1/relation").asText());
- assertEquals("N", res.at("/query/attr/operands/0/operands/0/key").asText());
- assertEquals("A", res.at("/query/attr/operands/0/operands/1/key").asText());
- assertEquals("V", res.at("/query/attr/operands/0/operands/2/key").asText());
- assertEquals("match:ne", res.at("/query/attr/operands/0/operands/2/match").asText());
- assertEquals("Genre", res.at("/query/attr/operands/1/operands/0/layer").asText());
- assertEquals("Sport", res.at("/query/attr/operands/1/operands/0/key").asText());
- assertEquals("Genre", res.at("/query/attr/operands/1/operands/1/layer").asText());
- assertEquals("Politik", res.at("/query/attr/operands/1/operands/1/key").asText());
- assertEquals("match:ne", res.at("/query/attr/operands/1/operands/1/match").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("w", res.at("/query/key").asText());
+ assertEquals("koral:termGroup", res.at("/query/attr/@type").asText());
+ assertEquals("relation:and", res.at("/query/attr/relation").asText());
+ assertEquals("koral:termGroup", res.at("/query/attr/operands/0/@type")
+ .asText());
+ assertEquals("relation:and", res.at("/query/attr/operands/0/relation")
+ .asText());
+ assertEquals("koral:termGroup", res.at("/query/attr/operands/1/@type")
+ .asText());
+ assertEquals("relation:and", res.at("/query/attr/operands/1/relation")
+ .asText());
+ assertEquals("N", res.at("/query/attr/operands/0/operands/0/key")
+ .asText());
+ assertEquals("A", res.at("/query/attr/operands/0/operands/1/key")
+ .asText());
+ assertEquals("V", res.at("/query/attr/operands/0/operands/2/key")
+ .asText());
+ assertEquals("match:ne",
+ res.at("/query/attr/operands/0/operands/2/match").asText());
+ assertEquals("Genre", res.at("/query/attr/operands/1/operands/0/layer")
+ .asText());
+ assertEquals("Sport", res.at("/query/attr/operands/1/operands/0/key")
+ .asText());
+ assertEquals("Genre", res.at("/query/attr/operands/1/operands/1/layer")
+ .asText());
+ assertEquals("Politik", res.at("/query/attr/operands/1/operands/1/key")
+ .asText());
+ assertEquals("match:ne",
+ res.at("/query/attr/operands/1/operands/1/match").asText());
}
+
+
@Test
- public void testOPALL() throws JsonProcessingException, IOException {
+ public void testOPALL () throws JsonProcessingException, IOException {
query = "#ALL(gehen /w1:10 voran)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("gehen", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("voran", res.at("/query/operands/1/wrap/key").asText());
- assertEquals("koral:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("w", res.at("/query/distances/0/key").asText());
- assertEquals(1, res.at("/query/distances/0/boundary/min").asInt());
- assertEquals(10, res.at("/query/distances/0/boundary/max").asInt());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("gehen", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("voran", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("w", res.at("/query/distances/0/key").asText());
+ assertEquals(1, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(10, res.at("/query/distances/0/boundary/max").asInt());
query = "#ALL(gehen /w1:10 (voran /w1:4 schnell))";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:distance", res.at("/query/distances/0/@type").asText());
- assertEquals("w", res.at("/query/distances/0/key").asText());
- assertEquals(1, res.at("/query/distances/0/boundary/min").asInt());
- assertEquals(10, res.at("/query/distances/0/boundary/max").asInt());
- assertEquals("gehen", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operands/1/operation").asText());
- assertEquals("koral:distance", res.at("/query/operands/1/distances/0/@type").asText());
- assertEquals("w", res.at("/query/operands/1/distances/0/key").asText());
- assertEquals(1, res.at("/query/operands/1/distances/0/boundary/min").asInt());
- assertEquals(4, res.at("/query/operands/1/distances/0/boundary/max").asInt());
- assertEquals("voran", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals("schnell", res.at("/query/operands/1/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("cosmas:distance", res.at("/query/distances/0/@type")
+ .asText());
+ assertEquals("w", res.at("/query/distances/0/key").asText());
+ assertEquals(1, res.at("/query/distances/0/boundary/min").asInt());
+ assertEquals(10, res.at("/query/distances/0/boundary/max").asInt());
+ assertEquals("gehen", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:sequence", res
+ .at("/query/operands/1/operation").asText());
+ assertEquals("cosmas:distance",
+ res.at("/query/operands/1/distances/0/@type").asText());
+ assertEquals("w", res.at("/query/operands/1/distances/0/key").asText());
+ assertEquals(1, res.at("/query/operands/1/distances/0/boundary/min")
+ .asInt());
+ assertEquals(4, res.at("/query/operands/1/distances/0/boundary/max")
+ .asInt());
+ assertEquals("voran", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("schnell", res.at("/query/operands/1/operands/1/wrap/key")
+ .asText());
}
+
@Test
- public void testOPNHIT() throws JsonProcessingException, IOException {
+ public void testOPNHIT () throws JsonProcessingException, IOException {
query = "#NHIT(gehen /w1:10 voran)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals(129, res.at("/query/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operation").asText());
- assertEquals("classRefOp:inversion",res.at("/query/operands/0/classRefOp").asText());
- assertEquals(130, res.at("/query/operands/0/classIn/0").asInt());
- assertEquals(131, res.at("/query/operands/0/classIn/1").asInt());
- assertEquals(129, res.at("/query/operands/0/classOut").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("koral:distance", res.at("/query/operands/0/operands/0/distances/0/@type").asText());
- assertEquals("w", res.at("/query/operands/0/operands/0/distances/0/key").asText());
- assertEquals(1, res.at("/query/operands/0/operands/0/distances/0/boundary/min").asInt());
- assertEquals(10, res.at("/query/operands/0/operands/0/distances/0/boundary/max").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/0/operation").asText());
- assertEquals(130, res.at("/query/operands/0/operands/0/operands/0/classOut").asInt());
- assertEquals(131, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
- assertEquals("koral:token", res.at("/query/operands/0/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("gehen", res.at("/query/operands/0/operands/0/operands/0/operands/0/wrap/key").asText());
- assertEquals("voran", res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals(129, res.at("/query/classRef/0").asInt());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:class", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals("classRefOp:inversion",
+ res.at("/query/operands/0/classRefOp").asText());
+ assertEquals(130, res.at("/query/operands/0/classIn/0").asInt());
+ assertEquals(131, res.at("/query/operands/0/classIn/1").asInt());
+ assertEquals(129, res.at("/query/operands/0/classOut").asInt());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:sequence",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("cosmas:distance",
+ res.at("/query/operands/0/operands/0/distances/0/@type")
+ .asText());
+ assertEquals("w", res
+ .at("/query/operands/0/operands/0/distances/0/key").asText());
+ assertEquals(1,
+ res.at("/query/operands/0/operands/0/distances/0/boundary/min")
+ .asInt());
+ assertEquals(10,
+ res.at("/query/operands/0/operands/0/distances/0/boundary/max")
+ .asInt());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(130,
+ res.at("/query/operands/0/operands/0/operands/0/classOut")
+ .asInt());
+ assertEquals(131,
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "koral:token",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals(
+ "gehen",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals(
+ "voran",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
query = "#NHIT(gehen /w1:10 voran /w1:10 Beispiel)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals(129, res.at("/query/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operation").asText());
- assertEquals("classRefOp:inversion",res.at("/query/operands/0/classRefOp").asText());
- assertEquals(130, res.at("/query/operands/0/classIn/0").asInt());
- assertEquals(131, res.at("/query/operands/0/classIn/1").asInt());
- assertEquals(129, res.at("/query/operands/0/classOut").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("koral:distance", res.at("/query/operands/0/operands/0/distances/0/@type").asText());
- assertEquals("w", res.at("/query/operands/0/operands/0/distances/0/key").asText());
- assertEquals(1, res.at("/query/operands/0/operands/0/distances/0/boundary/min").asInt());
- assertEquals(10, res.at("/query/operands/0/operands/0/distances/0/boundary/max").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/0/operation").asText());
- assertEquals(130, res.at("/query/operands/0/operands/0/operands/0/classOut").asInt());
- assertEquals("gehen", res.at("/query/operands/0/operands/0/operands/0/operands/0/wrap/key").asText());
- assertEquals(131, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals(129, res.at("/query/classRef/0").asInt());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:class", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals("classRefOp:inversion",
+ res.at("/query/operands/0/classRefOp").asText());
+ assertEquals(130, res.at("/query/operands/0/classIn/0").asInt());
+ assertEquals(131, res.at("/query/operands/0/classIn/1").asInt());
+ assertEquals(129, res.at("/query/operands/0/classOut").asInt());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:sequence",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("cosmas:distance",
+ res.at("/query/operands/0/operands/0/distances/0/@type")
+ .asText());
+ assertEquals("w", res
+ .at("/query/operands/0/operands/0/distances/0/key").asText());
+ assertEquals(1,
+ res.at("/query/operands/0/operands/0/distances/0/boundary/min")
+ .asInt());
+ assertEquals(10,
+ res.at("/query/operands/0/operands/0/distances/0/boundary/max")
+ .asInt());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(130,
+ res.at("/query/operands/0/operands/0/operands/0/classOut")
+ .asInt());
+ assertEquals(
+ "gehen",
+ res.at("/query/operands/0/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals(131,
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
// assertEquals("classRefOp:merge", res.at("/query/operands/0/operands/0/operands/1/classRefOp").asText());
- assertEquals("operation:sequence", res.at("/query/operands/0/operands/0/operands/1/operands/0/operation").asText());
- assertEquals(132, res.at("/query/operands/0/operands/0/operands/1/operands/0/operands/0/classOut").asInt());
- assertEquals("voran", res.at("/query/operands/0/operands/0/operands/1/operands/0/operands/0/operands/0/wrap/key").asText());
- assertEquals(132, res.at("/query/operands/0/operands/0/operands/1/operands/0/operands/1/classOut").asInt());
- assertEquals("Beispiel", res.at("/query/operands/0/operands/0/operands/1/operands/0/operands/1/operands/0/wrap/key").asText());
+ assertEquals(
+ "operation:sequence",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/operation")
+ .asText());
+ assertEquals(
+ 132,
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/operands/0/classOut")
+ .asInt());
+ assertEquals(
+ "voran",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals(
+ 132,
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "Beispiel",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
}
+
@Test
- public void testOPBED() throws JsonProcessingException, IOException {
+ public void testOPBED () throws JsonProcessingException, IOException {
query = "#BED(der , sa)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals(129, res.at("/query/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operation").asText());
- assertEquals("frames:startsWith", res.at("/query/operands/0/frames/0").asText());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/1/classOut").asInt());
- assertEquals("koral:token", res.at("/query/operands/0/operands/1/operands/0/@type").asText());
- assertEquals("der", res.at("/query/operands/0/operands/1/operands/0/wrap/key").asText());
- assertEquals("koral:span", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("s", res.at("/query/operands/0/operands/0/key").asText());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals(129, res.at("/query/classRef/0").asInt());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:position", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("frames:startsWith", res.at("/query/operands/0/frames/0")
+ .asText());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/1/operation").asText());
+ assertEquals(129, res.at("/query/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals("koral:token",
+ res.at("/query/operands/0/operands/1/operands/0/@type")
+ .asText());
+ assertEquals("der",
+ res.at("/query/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("koral:span", res.at("/query/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("s", res.at("/query/operands/0/operands/0/key").asText());
query = "#BED(der Mann , +pe)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals(129, res.at("/query/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operation").asText());
- assertEquals("frames:matches", res.at("/query/operands/0/frames/0").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals(-1, res.at("/query/operands/0/operands/0/spanRef/0").asInt());
- assertEquals(1, res.at("/query/operands/0/operands/0/spanRef/1").asInt());
- assertEquals("koral:span", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("p", res.at("/query/operands/0/operands/0/operands/0/key").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/operands/1/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operands/1/operation").asText());
- assertEquals(0, res.at("/query/operands/0/operands/1/spanRef/0").asInt());
- assertEquals(1, res.at("/query/operands/0/operands/1/spanRef/1").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/operands/1/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/1/operands/0/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/1/operands/0/classOut").asInt());
- assertEquals("operation:sequence", res.at("/query/operands/0/operands/1/operands/0/operands/0/operation").asText());
- assertEquals("der", res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/0/wrap/key").asText());
- assertEquals("Mann", res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/1/wrap/key").asText());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals(129, res.at("/query/classRef/0").asInt());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:position", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("frames:matches", res.at("/query/operands/0/frames/0")
+ .asText());
+ assertEquals("koral:reference",
+ res.at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:focus",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals(-1, res.at("/query/operands/0/operands/0/spanRef/0")
+ .asInt());
+ assertEquals(1, res.at("/query/operands/0/operands/0/spanRef/1")
+ .asInt());
+ assertEquals("koral:span",
+ res.at("/query/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("p", res.at("/query/operands/0/operands/0/operands/0/key")
+ .asText());
+ assertEquals("koral:reference",
+ res.at("/query/operands/0/operands/1/@type").asText());
+ assertEquals("operation:focus",
+ res.at("/query/operands/0/operands/1/operation").asText());
+ assertEquals(0, res.at("/query/operands/0/operands/1/spanRef/0")
+ .asInt());
+ assertEquals(1, res.at("/query/operands/0/operands/1/spanRef/1")
+ .asInt());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/1/operands/0/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/1/operands/0/operation")
+ .asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/1/operands/0/classOut")
+ .asInt());
+ assertEquals(
+ "operation:sequence",
+ res.at("/query/operands/0/operands/1/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(
+ "der",
+ res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals(
+ "Mann",
+ res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/1/wrap/key")
+ .asText());
query = "#BED(der Mann , sa,-pa)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals(129, res.at("/query/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operation").asText());
- assertEquals("frames:matches", res.at("/query/operands/0/frames/0").asText());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals(129, res.at("/query/classRef/0").asInt());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:position", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("frames:matches", res.at("/query/operands/0/frames/0")
+ .asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("frames:startsWith", res.at("/query/operands/0/operands/0/frames/0").asText());
- assertEquals("koral:span", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
- assertEquals("operation:sequence", res.at("/query/operands/0/operands/0/operands/1/operands/0/operation").asText());
- assertEquals("der", res.at("/query/operands/0/operands/0/operands/1/operands/0/operands/0/wrap/key").asText());
- assertEquals("Mann", res.at("/query/operands/0/operands/0/operands/1/operands/0/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:position",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("frames:startsWith",
+ res.at("/query/operands/0/operands/0/frames/0").asText());
+ assertEquals("koral:span",
+ res.at("/query/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/key")
+ .asText());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/0/operands/1/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "operation:sequence",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/operation")
+ .asText());
+ assertEquals(
+ "der",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals(
+ "Mann",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/operands/1/wrap/key")
+ .asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/1/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operands/1/operation").asText());
- assertEquals("frames:startsWith", res.at("/query/operands/0/operands/1/frames/0").asText());
- assertEquals(true, res.at("/query/operands/0/operands/1/exclude").asBoolean());
- assertEquals("koral:span", res.at("/query/operands/0/operands/1/operands/0/@type").asText());
- assertEquals("p", res.at("/query/operands/0/operands/1/operands/0/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/1/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/1/operands/1/operation").asText());
- assertEquals(130, res.at("/query/operands/0/operands/1/operands/1/classOut").asInt());
- assertEquals("operation:sequence", res.at("/query/operands/0/operands/1/operands/1/operands/0/operation").asText());
- assertEquals("der", res.at("/query/operands/0/operands/1/operands/1/operands/0/operands/0/wrap/key").asText());
- assertEquals("Mann", res.at("/query/operands/0/operands/1/operands/1/operands/0/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/1/@type").asText());
+ assertEquals("operation:position",
+ res.at("/query/operands/0/operands/1/operation").asText());
+ assertEquals("frames:startsWith",
+ res.at("/query/operands/0/operands/1/frames/0").asText());
+ assertEquals(true, res.at("/query/operands/0/operands/1/exclude")
+ .asBoolean());
+ assertEquals("koral:span",
+ res.at("/query/operands/0/operands/1/operands/0/@type")
+ .asText());
+ assertEquals("p", res.at("/query/operands/0/operands/1/operands/0/key")
+ .asText());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/1/operands/1/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/1/operands/1/operation")
+ .asText());
+ assertEquals(130,
+ res.at("/query/operands/0/operands/1/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "operation:sequence",
+ res.at("/query/operands/0/operands/1/operands/1/operands/0/operation")
+ .asText());
+ assertEquals(
+ "der",
+ res.at("/query/operands/0/operands/1/operands/1/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals(
+ "Mann",
+ res.at("/query/operands/0/operands/1/operands/1/operands/0/operands/1/wrap/key")
+ .asText());
}
+
@Test
- public void testColonSeparatedConditions() throws JsonProcessingException, IOException {
+ public void testColonSeparatedConditions () throws JsonProcessingException,
+ IOException {
query = "der:sa";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals(129, res.at("/query/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operation").asText());
- assertEquals("frames:startsWith", res.at("/query/operands/0/frames/0").asText());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/1/classOut").asInt());
- assertEquals("koral:token", res.at("/query/operands/0/operands/1/operands/0/@type").asText());
- assertEquals("der", res.at("/query/operands/0/operands/1/operands/0/wrap/key").asText());
- assertEquals("koral:span", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("s", res.at("/query/operands/0/operands/0/key").asText());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals(129, res.at("/query/classRef/0").asInt());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:position", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("frames:startsWith", res.at("/query/operands/0/frames/0")
+ .asText());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/1/operation").asText());
+ assertEquals(129, res.at("/query/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals("koral:token",
+ res.at("/query/operands/0/operands/1/operands/0/@type")
+ .asText());
+ assertEquals("der",
+ res.at("/query/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("koral:span", res.at("/query/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("s", res.at("/query/operands/0/operands/0/key").asText());
query = "der:sa,-pa";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals(129, res.at("/query/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operation").asText());
- assertEquals("frames:matches", res.at("/query/operands/0/frames/0").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("frames:startsWith", res.at("/query/operands/0/operands/0/frames/0").asText());
- assertEquals("koral:span", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
- assertEquals("der", res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/1/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operands/1/operation").asText());
- assertEquals("frames:startsWith", res.at("/query/operands/0/operands/1/frames/0").asText());
- assertEquals(true, res.at("/query/operands/0/operands/1/exclude").asBoolean());
- assertEquals("koral:span", res.at("/query/operands/0/operands/1/operands/0/@type").asText());
- assertEquals("p", res.at("/query/operands/0/operands/1/operands/0/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/1/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/1/operands/1/operation").asText());
- assertEquals(130, res.at("/query/operands/0/operands/1/operands/1/classOut").asInt());
- assertEquals("der", res.at("/query/operands/0/operands/1/operands/1/operands/0/wrap/key").asText());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals(129, res.at("/query/classRef/0").asInt());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:position", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("frames:matches", res.at("/query/operands/0/frames/0")
+ .asText());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:position",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("frames:startsWith",
+ res.at("/query/operands/0/operands/0/frames/0").asText());
+ assertEquals("koral:span",
+ res.at("/query/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/key")
+ .asText());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/0/operands/1/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "der",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/1/@type").asText());
+ assertEquals("operation:position",
+ res.at("/query/operands/0/operands/1/operation").asText());
+ assertEquals("frames:startsWith",
+ res.at("/query/operands/0/operands/1/frames/0").asText());
+ assertEquals(true, res.at("/query/operands/0/operands/1/exclude")
+ .asBoolean());
+ assertEquals("koral:span",
+ res.at("/query/operands/0/operands/1/operands/0/@type")
+ .asText());
+ assertEquals("p", res.at("/query/operands/0/operands/1/operands/0/key")
+ .asText());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/1/operands/1/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/1/operands/1/operation")
+ .asText());
+ assertEquals(130,
+ res.at("/query/operands/0/operands/1/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "der",
+ res.at("/query/operands/0/operands/1/operands/1/operands/0/wrap/key")
+ .asText());
query = "der:sa,-pa,+te";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals(129, res.at("/query/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operation").asText());
- assertEquals("frames:matches", res.at("/query/operands/0/frames/0").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operands/0/operation").asText());
- assertEquals("frames:startsWith", res.at("/query/operands/0/operands/0/frames/0").asText());
- assertEquals("koral:span", res.at("/query/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/0/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/0/operands/1/operation").asText());
- assertEquals(129, res.at("/query/operands/0/operands/0/operands/1/classOut").asInt());
- assertEquals("der", res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/operands/1/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operands/1/operation").asText());
- assertEquals(130, res.at("/query/operands/0/operands/1/classRef/0").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/operands/1/operands/0/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operands/1/operands/0/operation").asText());
- assertEquals("frames:matches", res.at("/query/operands/0/operands/1/operands/0/frames/0").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/1/operands/0/operands/0/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operands/1/operands/0/operands/0/operation").asText());
- assertEquals("frames:startsWith", res.at("/query/operands/0/operands/1/operands/0/operands/0/frames/0").asText());
- assertEquals(true, res.at("/query/operands/0/operands/1/operands/0/operands/0/exclude").asBoolean());
- assertEquals("koral:span", res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/0/@type").asText());
- assertEquals("p", res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/0/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/1/operation").asText());
- assertEquals(130, res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/1/classOut").asInt());
- assertEquals("der", res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/1/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/operands/1/operands/0/operands/1/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operands/1/operands/0/operands/1/operation").asText());
- assertEquals("frames:matches", res.at("/query/operands/0/operands/1/operands/0/operands/1/frames/0").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operation").asText());
- assertEquals(-1, res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/spanRef/0").asInt());
- assertEquals(1, res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/spanRef/1").asInt());
- assertEquals("koral:span", res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operands/0/@type").asText());
- assertEquals("t", res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operands/0/key").asText());
- assertEquals("koral:reference", res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/1/@type").asText());
- assertEquals("operation:focus", res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/1/operation").asText());
- assertEquals(0, res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/1/spanRef/0").asInt());
- assertEquals(1, res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/1/spanRef/1").asInt());
- assertEquals("koral:group", res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/1/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/1/operands/0/operation").asText());
- assertEquals(131, res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/1/operands/0/classOut").asInt());
- assertEquals("der", res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/1/operands/0/operands/0/wrap/key").asText());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals(129, res.at("/query/classRef/0").asInt());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:position", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("frames:matches", res.at("/query/operands/0/frames/0")
+ .asText());
+ assertEquals("koral:group", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("operation:position",
+ res.at("/query/operands/0/operands/0/operation").asText());
+ assertEquals("frames:startsWith",
+ res.at("/query/operands/0/operands/0/frames/0").asText());
+ assertEquals("koral:span",
+ res.at("/query/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals("s", res.at("/query/operands/0/operands/0/operands/0/key")
+ .asText());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/0/operands/1/@type")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(129,
+ res.at("/query/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "der",
+ res.at("/query/operands/0/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("koral:reference",
+ res.at("/query/operands/0/operands/1/@type").asText());
+ assertEquals("operation:focus",
+ res.at("/query/operands/0/operands/1/operation").asText());
+ assertEquals(130, res.at("/query/operands/0/operands/1/classRef/0")
+ .asInt());
+ assertEquals("koral:group",
+ res.at("/query/operands/0/operands/1/operands/0/@type")
+ .asText());
+ assertEquals("operation:position",
+ res.at("/query/operands/0/operands/1/operands/0/operation")
+ .asText());
+ assertEquals("frames:matches",
+ res.at("/query/operands/0/operands/1/operands/0/frames/0")
+ .asText());
+ assertEquals(
+ "koral:group",
+ res.at("/query/operands/0/operands/1/operands/0/operands/0/@type")
+ .asText());
+ assertEquals(
+ "operation:position",
+ res.at("/query/operands/0/operands/1/operands/0/operands/0/operation")
+ .asText());
+ assertEquals(
+ "frames:startsWith",
+ res.at("/query/operands/0/operands/1/operands/0/operands/0/frames/0")
+ .asText());
+ assertEquals(
+ true,
+ res.at("/query/operands/0/operands/1/operands/0/operands/0/exclude")
+ .asBoolean());
+ assertEquals(
+ "koral:span",
+ res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/0/@type")
+ .asText());
+ assertEquals(
+ "p",
+ res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/0/key")
+ .asText());
+ assertEquals(
+ "koral:group",
+ res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/1/@type")
+ .asText());
+ assertEquals(
+ "operation:class",
+ res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(
+ 130,
+ res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "der",
+ res.at("/query/operands/0/operands/1/operands/0/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals(
+ "koral:group",
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/@type")
+ .asText());
+ assertEquals(
+ "operation:position",
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(
+ "frames:matches",
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/frames/0")
+ .asText());
+ assertEquals(
+ "koral:reference",
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/@type")
+ .asText());
+ assertEquals(
+ "operation:focus",
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operation")
+ .asText());
+ assertEquals(
+ -1,
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/spanRef/0")
+ .asInt());
+ assertEquals(
+ 1,
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/spanRef/1")
+ .asInt());
+ assertEquals(
+ "koral:span",
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operands/0/@type")
+ .asText());
+ assertEquals(
+ "t",
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operands/0/key")
+ .asText());
+ assertEquals(
+ "koral:reference",
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/1/@type")
+ .asText());
+ assertEquals(
+ "operation:focus",
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/1/operation")
+ .asText());
+ assertEquals(
+ 0,
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/1/spanRef/0")
+ .asInt());
+ assertEquals(
+ 1,
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/1/spanRef/1")
+ .asInt());
+ assertEquals(
+ "koral:group",
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/1/operands/0/@type")
+ .asText());
+ assertEquals(
+ "operation:class",
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/1/operands/0/operation")
+ .asText());
+ assertEquals(
+ 131,
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/1/operands/0/classOut")
+ .asInt());
+ assertEquals(
+ "der",
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/1/operands/0/operands/0/wrap/key")
+ .asText());
}
+
@Test
- public void testErrors() throws JsonProcessingException, IOException {
+ public void testErrors () throws JsonProcessingException, IOException {
query = "MORPH(tt/p=\"\")";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals(true, res.at("/query/@type").isMissingNode());
- assertEquals(StatusCodes.INCOMPATIBLE_OPERATOR_AND_OPERAND, res.at("/errors/0/0").asInt());
- assertTrue(res.at("/errors/0/1").asText().startsWith("Something went wrong parsing the argument in MORPH()"));
+ assertEquals(true, res.at("/query/@type").isMissingNode());
+ assertEquals(StatusCodes.INCOMPATIBLE_OPERATOR_AND_OPERAND,
+ res.at("/errors/0/0").asInt());
+ assertTrue(res
+ .at("/errors/0/1")
+ .asText()
+ .startsWith(
+ "Something went wrong parsing the argument in MORPH()"));
query = "MORPH(tt/p=\"foo)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals(true, res.at("/query/@type").isMissingNode());
- assertEquals(StatusCodes.MALFORMED_QUERY, res.at("/errors/0/0").asInt());
- assertTrue(res.at("/errors/0/1").asText().startsWith("Early closing parenthesis"));
+ assertEquals(true, res.at("/query/@type").isMissingNode());
+ assertEquals(StatusCodes.MALFORMED_QUERY, res.at("/errors/0/0").asInt());
+ assertTrue(res.at("/errors/0/1").asText()
+ .startsWith("Early closing parenthesis"));
query = "MORPH(tt/p=)";
qs.setQuery(query, "cosmas2");
res = mapper.readTree(qs.toJSON());
- assertEquals(true, res.at("/query/@type").isMissingNode());
- assertEquals(StatusCodes.MALFORMED_QUERY, res.at("/errors/0/0").asInt());
- assertTrue(res.at("/errors/0/1").asText().startsWith("Early closing parenthesis"));
+ assertEquals(true, res.at("/query/@type").isMissingNode());
+ assertEquals(StatusCodes.MALFORMED_QUERY, res.at("/errors/0/0").asInt());
+ assertTrue(res.at("/errors/0/1").asText()
+ .startsWith("Early closing parenthesis"));
}
}
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/CqlQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/CqlQueryProcessorTest.java
index 92cf788..6f2bdd9 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/CqlQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/CqlQueryProcessorTest.java
@@ -1,4 +1,5 @@
package de.ids_mannheim.korap.query.serialize;
+
import static org.junit.Assert.assertEquals;
import java.io.IOException;
@@ -14,187 +15,206 @@
public class CqlQueryProcessorTest {
-
- String query;
- String version ="1.2";
- ObjectMapper mapper = new ObjectMapper();
-
- @Test
- public void testExceptions() throws CQLParseException, IOException {
- query = "(Kuh) prox (Germ) ";
- try {
- CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
- } catch (Exception e) {
- int errorCode = Integer.parseInt(e.getMessage().split(":")[0].replace("SRU diagnostic ", ""));
- assertEquals(48,errorCode);
- }
-
- query = "(Kuh) or/rel.combine=sum (Germ) ";
- try {
- CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
- }catch (Exception e) {
- int errorCode = Integer.parseInt(e.getMessage().split(":")[0].replace("SRU diagnostic ", ""));
- assertEquals(20,errorCode);
- }
-
- query = "dc.title any Germ ";
- try {
- CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
- } catch (Exception e) {
- int errorCode = Integer.parseInt(e.getMessage().split(":")[0].replace("SRU diagnostic ", ""));
- assertEquals(16,errorCode);
- }
-
- query = "cql.serverChoice any Germ ";
- try {
- CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
- } catch (Exception e) {
- int errorCode = Integer.parseInt(e.getMessage().split(":")[0].replace("SRU diagnostic ", ""));
- assertEquals(19,errorCode);
- }
-
- query = "";
- try {
- CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
- } catch (Exception e) {
- int errorCode = Integer.parseInt(e.getMessage().split(":")[0].replace("SRU diagnostic ", ""));
- assertEquals(27,errorCode);
- }
- }
-
- @Test
- public void testAndQuery() throws CQLParseException, IOException, Exception{
- query="(Sonne) and (scheint)";
- String jsonLd =
- "{@type : koral:group, operation : operation:sequence, inOrder : false," +
- "distances:[ "+
- "{@type : koral:distance, key : s, min : 0, max : 0 } ],"+
- "operands : ["+
- "{@type : koral:token, wrap : {@type : koral:term,key : Sonne, layer : orth, match : match:eq}}," +
- "{@type : koral:token,wrap : {@type : koral:term,key : scheint,layer : orth,match : match:eq}" +
- "}]}";
-
- CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
- String serializedQuery = mapper.writeValueAsString(cqlTree.getRequestMap().get("query"));
- assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
-// /System.out.println(serializedQuery);
- //CosmasTree ct = new CosmasTree("Sonne und scheint");
- //serializedQuery = mapper.writeValueAsString(ct.getRequestMap().get("query"));
- //assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
- }
-
- @Test
- public void testBooleanQuery() throws CQLParseException, IOException, Exception{
- query="((Sonne) or (Mond)) and (scheint)";
- String jsonLd =
- "{@type:koral:group, operation:operation:sequence, inOrder : false, distances:[" +
- "{@type:koral:distance, key:s, min:0, max:0}" +
- "], operands:[" +
- "{@type:koral:group, operation:operation:or, operands:[" +
- "{@type:koral:token, wrap:{@type:koral:term, key:Sonne, layer:orth, match:match:eq}}," +
- "{@type:koral:token, wrap:{@type:koral:term, key:Mond, layer:orth, match:match:eq}}" +
- "]}," +
- "{@type:koral:token, wrap:{@type:koral:term, key:scheint, layer:orth, match:match:eq}}" +
- "]}";
- CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
- String serializedQuery = mapper.writeValueAsString(cqlTree.getRequestMap().get("query"));
- assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
-
-
- query="(scheint) and ((Sonne) or (Mond))";
- jsonLd =
- "{@type:koral:group, operation:operation:sequence, inOrder : false, distances:[" +
- "{@type:koral:distance, key:s, min:0, max:0}" +
- "], operands:[" +
- "{@type:koral:token, wrap:{@type:koral:term, key:scheint, layer:orth, match:match:eq}}," +
- "{@type:koral:group, operation:operation:or, operands:[" +
- "{@type:koral:token, wrap:{@type:koral:term, key:Sonne, layer:orth, match:match:eq}}," +
- "{@type:koral:token, wrap:{@type:koral:term, key:Mond, layer:orth, match:match:eq}}" +
- "]}" +
- "]}";
- cqlTree = new CqlQueryProcessor(query, version);
- serializedQuery = mapper.writeValueAsString(cqlTree.getRequestMap().get("query"));
- assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
-
- }
-
- @Test
- public void testOrQuery() throws CQLParseException, IOException, Exception{
- query = "(Sonne) or (Mond)";
- String jsonLd =
- "{@type:koral:group, operation:operation:or, operands:[" +
- "{@type:koral:token, wrap:{@type:koral:term, key:Sonne, layer:orth, match:match:eq}}," +
- "{@type:koral:token, wrap:{@type:koral:term, key:Mond, layer:orth, match:match:eq}}" +
- "]}";
-
- CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
- String serializedQuery = mapper.writeValueAsString(cqlTree.getRequestMap().get("query"));
- assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
-
- query="(\"Sonne scheint\") or (Mond)";
- jsonLd =
- "{@type:koral:group, operation:operation:or, operands:[" +
- "{@type:koral:group, operation:operation:sequence, operands:[" +
- "{@type:koral:token, wrap:{@type:koral:term, key:Sonne, layer:orth, match:match:eq}}," +
- "{@type:koral:token, wrap:{@type:koral:term, key:scheint, layer:orth, match:match:eq}}" +
- "]}," +
- "{@type:koral:token, wrap:{@type:koral:term, key:Mond, layer:orth, match:match:eq}}" +
- "]}";
-
- cqlTree = new CqlQueryProcessor(query, version);
- serializedQuery = mapper.writeValueAsString(cqlTree.getRequestMap().get("query"));
- assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
-
- query="(\"Sonne scheint\") or (\"Mond scheint\")";
- jsonLd =
- "{@type:koral:group, operation:operation:or, operands:[" +
- "{@type:koral:group, operation:operation:sequence, operands:[" +
- "{@type:koral:token, wrap:{@type:koral:term, key:Sonne, layer:orth, match:match:eq}}," +
- "{@type:koral:token, wrap:{@type:koral:term, key:scheint, layer:orth, match:match:eq}}" +
- "]}," +
- "{@type:koral:group, operation:operation:sequence, operands:[" +
- "{@type:koral:token, wrap:{@type:koral:term, key:Mond, layer:orth, match:match:eq}}," +
- "{@type:koral:token, wrap:{@type:koral:term, key:scheint, layer:orth, match:match:eq}}" +
- "]}" +
- "]}";
- cqlTree = new CqlQueryProcessor(query, version);
- serializedQuery = mapper.writeValueAsString(cqlTree.getRequestMap().get("query"));
- assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
- }
-
- @Test
- public void testTermQuery() throws CQLParseException, IOException, Exception{
- query = "Sonne";
- String jsonLd = "{@type:koral:token, wrap:{@type:koral:term, key:Sonne, layer:orth, match:match:eq}}";
- CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
- String serializedQuery = mapper.writeValueAsString(cqlTree.getRequestMap().get("query"));
- assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
- }
-
- @Test
- public void testPhraseQuery() throws CQLParseException, IOException, Exception{
- query="\"der Mann\"";
- String jsonLd =
- "{@type:koral:group, operation:operation:sequence, operands:[" +
- "{@type:koral:token, wrap:{@type:koral:term, key:der, layer:orth, match:match:eq}}," +
- "{@type:koral:token, wrap:{@type:koral:term, key:Mann, layer:orth, match:match:eq}}" +
- "]}";
-
- CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
- String serializedQuery = mapper.writeValueAsString(cqlTree.getRequestMap().get("query"));
- assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
-
-
- query="der Mann schläft";
- jsonLd =
- "{@type:koral:group, operation:operation:sequence, operands:[" +
- "{@type:koral:token, wrap:{@type:koral:term, key:der, layer:orth, match:match:eq}}," +
- "{@type:koral:token, wrap:{@type:koral:term, key:Mann, layer:orth, match:match:eq}}," +
- "{@type:koral:token, wrap:{@type:koral:term, key:schläft, layer:orth, match:match:eq}}" +
- "]}";
-
- cqlTree = new CqlQueryProcessor(query, version);
- serializedQuery = mapper.writeValueAsString(cqlTree.getRequestMap().get("query"));
- assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
- }
+
+ String query;
+ String version = "1.2";
+ ObjectMapper mapper = new ObjectMapper();
+
+
+ @Test
+ public void testExceptions () throws CQLParseException, IOException {
+ query = "(Kuh) prox (Germ) ";
+ try {
+ CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
+ }
+ catch (Exception e) {
+ int errorCode = Integer.parseInt(e.getMessage().split(":")[0]
+ .replace("SRU diagnostic ", ""));
+ assertEquals(48, errorCode);
+ }
+
+ query = "(Kuh) or/rel.combine=sum (Germ) ";
+ try {
+ CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
+ }
+ catch (Exception e) {
+ int errorCode = Integer.parseInt(e.getMessage().split(":")[0]
+ .replace("SRU diagnostic ", ""));
+ assertEquals(20, errorCode);
+ }
+
+ query = "dc.title any Germ ";
+ try {
+ CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
+ }
+ catch (Exception e) {
+ int errorCode = Integer.parseInt(e.getMessage().split(":")[0]
+ .replace("SRU diagnostic ", ""));
+ assertEquals(16, errorCode);
+ }
+
+ query = "cql.serverChoice any Germ ";
+ try {
+ CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
+ }
+ catch (Exception e) {
+ int errorCode = Integer.parseInt(e.getMessage().split(":")[0]
+ .replace("SRU diagnostic ", ""));
+ assertEquals(19, errorCode);
+ }
+
+ query = "";
+ try {
+ CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
+ }
+ catch (Exception e) {
+ int errorCode = Integer.parseInt(e.getMessage().split(":")[0]
+ .replace("SRU diagnostic ", ""));
+ assertEquals(27, errorCode);
+ }
+ }
+
+
+ @Test
+ public void testAndQuery () throws CQLParseException, IOException,
+ Exception {
+ query = "(Sonne) and (scheint)";
+ String jsonLd = "{@type : koral:group, operation : operation:sequence, inOrder : false,"
+ + "distances:[ "
+ + "{@type : koral:distance, key : s, min : 0, max : 0 } ],"
+ + "operands : ["
+ + "{@type : koral:token, wrap : {@type : koral:term,key : Sonne, layer : orth, match : match:eq}},"
+ + "{@type : koral:token,wrap : {@type : koral:term,key : scheint,layer : orth,match : match:eq}"
+ + "}]}";
+
+ CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
+ String serializedQuery = mapper.writeValueAsString(cqlTree
+ .getRequestMap().get("query"));
+ assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
+ // /System.out.println(serializedQuery);
+ //CosmasTree ct = new CosmasTree("Sonne und scheint");
+ //serializedQuery = mapper.writeValueAsString(ct.getRequestMap().get("query"));
+ //assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
+ }
+
+
+ @Test
+ public void testBooleanQuery () throws CQLParseException, IOException,
+ Exception {
+ query = "((Sonne) or (Mond)) and (scheint)";
+ String jsonLd = "{@type:koral:group, operation:operation:sequence, inOrder : false, distances:["
+ + "{@type:koral:distance, key:s, min:0, max:0}"
+ + "], operands:["
+ + "{@type:koral:group, operation:operation:or, operands:["
+ + "{@type:koral:token, wrap:{@type:koral:term, key:Sonne, layer:orth, match:match:eq}},"
+ + "{@type:koral:token, wrap:{@type:koral:term, key:Mond, layer:orth, match:match:eq}}"
+ + "]},"
+ + "{@type:koral:token, wrap:{@type:koral:term, key:scheint, layer:orth, match:match:eq}}"
+ + "]}";
+ CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
+ String serializedQuery = mapper.writeValueAsString(cqlTree
+ .getRequestMap().get("query"));
+ assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
+
+
+ query = "(scheint) and ((Sonne) or (Mond))";
+ jsonLd = "{@type:koral:group, operation:operation:sequence, inOrder : false, distances:["
+ + "{@type:koral:distance, key:s, min:0, max:0}"
+ + "], operands:["
+ + "{@type:koral:token, wrap:{@type:koral:term, key:scheint, layer:orth, match:match:eq}},"
+ + "{@type:koral:group, operation:operation:or, operands:["
+ + "{@type:koral:token, wrap:{@type:koral:term, key:Sonne, layer:orth, match:match:eq}},"
+ + "{@type:koral:token, wrap:{@type:koral:term, key:Mond, layer:orth, match:match:eq}}"
+ + "]}" + "]}";
+ cqlTree = new CqlQueryProcessor(query, version);
+ serializedQuery = mapper.writeValueAsString(cqlTree.getRequestMap()
+ .get("query"));
+ assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
+
+ }
+
+
+ @Test
+ public void testOrQuery () throws CQLParseException, IOException, Exception {
+ query = "(Sonne) or (Mond)";
+ String jsonLd = "{@type:koral:group, operation:operation:or, operands:["
+ + "{@type:koral:token, wrap:{@type:koral:term, key:Sonne, layer:orth, match:match:eq}},"
+ + "{@type:koral:token, wrap:{@type:koral:term, key:Mond, layer:orth, match:match:eq}}"
+ + "]}";
+
+ CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
+ String serializedQuery = mapper.writeValueAsString(cqlTree
+ .getRequestMap().get("query"));
+ assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
+
+ query = "(\"Sonne scheint\") or (Mond)";
+ jsonLd = "{@type:koral:group, operation:operation:or, operands:["
+ + "{@type:koral:group, operation:operation:sequence, operands:["
+ + "{@type:koral:token, wrap:{@type:koral:term, key:Sonne, layer:orth, match:match:eq}},"
+ + "{@type:koral:token, wrap:{@type:koral:term, key:scheint, layer:orth, match:match:eq}}"
+ + "]},"
+ + "{@type:koral:token, wrap:{@type:koral:term, key:Mond, layer:orth, match:match:eq}}"
+ + "]}";
+
+ cqlTree = new CqlQueryProcessor(query, version);
+ serializedQuery = mapper.writeValueAsString(cqlTree.getRequestMap()
+ .get("query"));
+ assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
+
+ query = "(\"Sonne scheint\") or (\"Mond scheint\")";
+ jsonLd = "{@type:koral:group, operation:operation:or, operands:["
+ + "{@type:koral:group, operation:operation:sequence, operands:["
+ + "{@type:koral:token, wrap:{@type:koral:term, key:Sonne, layer:orth, match:match:eq}},"
+ + "{@type:koral:token, wrap:{@type:koral:term, key:scheint, layer:orth, match:match:eq}}"
+ + "]},"
+ + "{@type:koral:group, operation:operation:sequence, operands:["
+ + "{@type:koral:token, wrap:{@type:koral:term, key:Mond, layer:orth, match:match:eq}},"
+ + "{@type:koral:token, wrap:{@type:koral:term, key:scheint, layer:orth, match:match:eq}}"
+ + "]}" + "]}";
+ cqlTree = new CqlQueryProcessor(query, version);
+ serializedQuery = mapper.writeValueAsString(cqlTree.getRequestMap()
+ .get("query"));
+ assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
+ }
+
+
+ @Test
+ public void testTermQuery () throws CQLParseException, IOException,
+ Exception {
+ query = "Sonne";
+ String jsonLd = "{@type:koral:token, wrap:{@type:koral:term, key:Sonne, layer:orth, match:match:eq}}";
+ CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
+ String serializedQuery = mapper.writeValueAsString(cqlTree
+ .getRequestMap().get("query"));
+ assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
+ }
+
+
+ @Test
+ public void testPhraseQuery () throws CQLParseException, IOException,
+ Exception {
+ query = "\"der Mann\"";
+ String jsonLd = "{@type:koral:group, operation:operation:sequence, operands:["
+ + "{@type:koral:token, wrap:{@type:koral:term, key:der, layer:orth, match:match:eq}},"
+ + "{@type:koral:token, wrap:{@type:koral:term, key:Mann, layer:orth, match:match:eq}}"
+ + "]}";
+
+ CqlQueryProcessor cqlTree = new CqlQueryProcessor(query, version);
+ String serializedQuery = mapper.writeValueAsString(cqlTree
+ .getRequestMap().get("query"));
+ assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
+
+
+ query = "der Mann schläft";
+ jsonLd = "{@type:koral:group, operation:operation:sequence, operands:["
+ + "{@type:koral:token, wrap:{@type:koral:term, key:der, layer:orth, match:match:eq}},"
+ + "{@type:koral:token, wrap:{@type:koral:term, key:Mann, layer:orth, match:match:eq}},"
+ + "{@type:koral:token, wrap:{@type:koral:term, key:schläft, layer:orth, match:match:eq}}"
+ + "]}";
+
+ cqlTree = new CqlQueryProcessor(query, version);
+ serializedQuery = mapper.writeValueAsString(cqlTree.getRequestMap()
+ .get("query"));
+ assertEquals(jsonLd.replace(" ", ""), serializedQuery.replace("\"", ""));
+ }
}
diff --git a/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java b/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java
index b7858af..344e78c 100644
--- a/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java
+++ b/src/test/java/de/ids_mannheim/korap/query/serialize/PoliqarpPlusQueryProcessorTest.java
@@ -1,4 +1,5 @@
package de.ids_mannheim.korap.query.serialize;
+
import static org.junit.Assert.*;
import java.io.IOException;
@@ -11,11 +12,11 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.collect.Lists;
-
import de.ids_mannheim.korap.query.serialize.QuerySerializer;
/**
- * Tests for JSON-LD serialization of PoliqarpPlus queries.
+ * Tests for JSON-LD serialization of PoliqarpPlus queries.
+ *
* @author Joachim Bingel (bingel@ids-mannheim.de)
* @version 1.0
*/
@@ -28,8 +29,9 @@
ObjectMapper mapper = new ObjectMapper();
JsonNode res;
+
@Test
- public void testContext() throws JsonProcessingException, IOException {
+ public void testContext () throws JsonProcessingException, IOException {
query = "foo";
String contextString = "http://korap.ids-mannheim.de/ns/koral/0.3/context.jsonld";
qs.setQuery(query, "poliqarpplus");
@@ -37,1383 +39,1679 @@
assertEquals(contextString, res.get("@context").asText());
}
+
@Test
- public void testSingleTokens() throws JsonProcessingException, IOException {
+ public void testSingleTokens () throws JsonProcessingException, IOException {
query = "[base=Mann]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("Mann", res.at("/query/wrap/key").asText());
- assertEquals("lemma", res.at("/query/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("Mann", res.at("/query/wrap/key").asText());
+ assertEquals("lemma", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
query = "[orth!=Frau]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("Frau", res.at("/query/wrap/key").asText());
- assertEquals("orth", res.at("/query/wrap/layer").asText());
- assertEquals("match:ne", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("Frau", res.at("/query/wrap/key").asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("match:ne", res.at("/query/wrap/match").asText());
query = "[p!=NN]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("NN", res.at("/query/wrap/key").asText());
- assertEquals("p", res.at("/query/wrap/layer").asText());
- assertEquals("match:ne", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("NN", res.at("/query/wrap/key").asText());
+ assertEquals("p", res.at("/query/wrap/layer").asText());
+ assertEquals("match:ne", res.at("/query/wrap/match").asText());
query = "[!p!=NN]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("NN", res.at("/query/wrap/key").asText());
- assertEquals("p", res.at("/query/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("NN", res.at("/query/wrap/key").asText());
+ assertEquals("p", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
query = "[base=schland/x]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals(".*?schland.*?", res.at("/query/wrap/key").asText());
- assertEquals("lemma", res.at("/query/wrap/layer").asText());
- assertEquals("type:regex", res.at("/query/wrap/type").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals(".*?schland.*?", res.at("/query/wrap/key").asText());
+ assertEquals("lemma", res.at("/query/wrap/layer").asText());
+ assertEquals("type:regex", res.at("/query/wrap/type").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
}
+
@Test
- public void testNegatedTokens() throws JsonProcessingException, IOException {
+ public void testNegatedTokens () throws JsonProcessingException,
+ IOException {
query = "![p!=NN]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("NN", res.at("/query/wrap/key").asText());
- assertEquals("p", res.at("/query/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("NN", res.at("/query/wrap/key").asText());
+ assertEquals("p", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
}
-
+
+
@Test
- public void testValue() throws JsonProcessingException, IOException {
+ public void testValue () throws JsonProcessingException, IOException {
query = "[mate/m=temp:pres]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("temp", res.at("/query/wrap/key").asText());
- assertEquals("pres", res.at("/query/wrap/value").asText());
- assertEquals("m", res.at("/query/wrap/layer").asText());
- assertEquals("mate", res.at("/query/wrap/foundry").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("temp", res.at("/query/wrap/key").asText());
+ assertEquals("pres", res.at("/query/wrap/value").asText());
+ assertEquals("m", res.at("/query/wrap/layer").asText());
+ assertEquals("mate", res.at("/query/wrap/foundry").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
}
+
@Test
- public void testRegex() throws JsonProcessingException, IOException {
+ public void testRegex () throws JsonProcessingException, IOException {
query = "[orth=\"M(a|ä)nn(er)?\"]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("M(a|ä)nn(er)?", res.at("/query/wrap/key").asText());
- assertEquals("type:regex", res.at("/query/wrap/type").asText());
- assertEquals("orth", res.at("/query/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("M(a|ä)nn(er)?", res.at("/query/wrap/key").asText());
+ assertEquals("type:regex", res.at("/query/wrap/type").asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
query = "[orth=\"M(a|ä)nn(er)?\"/x]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals(".*?M(a|ä)nn(er)?.*?", res.at("/query/wrap/key").asText());
- assertEquals("type:regex", res.at("/query/wrap/type").asText());
- assertEquals("orth", res.at("/query/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals(".*?M(a|ä)nn(er)?.*?", res.at("/query/wrap/key").asText());
+ assertEquals("type:regex", res.at("/query/wrap/type").asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
query = "\".*?Mann.*?\"";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals(".*?Mann.*?", res.at("/query/wrap/key").asText());
- assertEquals("type:regex", res.at("/query/wrap/type").asText());
- assertEquals("orth", res.at("/query/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals(".*?Mann.*?", res.at("/query/wrap/key").asText());
+ assertEquals("type:regex", res.at("/query/wrap/type").asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
query = "z.B./x";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals(".*?z\\.B\\..*?", res.at("/query/wrap/key").asText());
- assertEquals("type:regex", res.at("/query/wrap/type").asText());
- assertEquals("orth", res.at("/query/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals(".*?z\\.B\\..*?", res.at("/query/wrap/key").asText());
+ assertEquals("type:regex", res.at("/query/wrap/type").asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
}
+
@Test
- public void testPunct() throws JsonProcessingException, IOException {
+ public void testPunct () throws JsonProcessingException, IOException {
query = "[punct=.]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals(".", res.at("/query/wrap/key").asText());
- assertEquals("type:punct", res.at("/query/wrap/type").asText());
- assertEquals("orth", res.at("/query/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
-
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals(".", res.at("/query/wrap/key").asText());
+ assertEquals("type:punct", res.at("/query/wrap/type").asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
+
query = "[punct=\".\"]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals(".", res.at("/query/wrap/key").asText());
- assertEquals("type:punct", res.at("/query/wrap/type").asText());
- assertEquals("orth", res.at("/query/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals(".", res.at("/query/wrap/key").asText());
+ assertEquals("type:punct", res.at("/query/wrap/type").asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
}
+
@Test
- public void testCaseSensitivityFlag() throws JsonProcessingException, IOException {
+ public void testCaseSensitivityFlag () throws JsonProcessingException,
+ IOException {
query = "[orth=deutscher/i]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("deutscher", res.at("/query/wrap/key").asText());
- assertEquals(true, res.at("/query/wrap/flags:caseInsensitive").isMissingNode());
- assertEquals("flags:caseInsensitive", res.at("/query/wrap/flags/0").asText());
- assertEquals("orth", res.at("/query/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("deutscher", res.at("/query/wrap/key").asText());
+ assertEquals(true, res.at("/query/wrap/flags:caseInsensitive")
+ .isMissingNode());
+ assertEquals("flags:caseInsensitive", res.at("/query/wrap/flags/0")
+ .asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
query = "deutscher/i";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("deutscher", res.at("/query/wrap/key").asText());
- assertEquals("flags:caseInsensitive", res.at("/query/wrap/flags/0").asText());
- assertEquals("orth", res.at("/query/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("deutscher", res.at("/query/wrap/key").asText());
+ assertEquals("flags:caseInsensitive", res.at("/query/wrap/flags/0")
+ .asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
query = "deutscher/I";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("deutscher", res.at("/query/wrap/key").asText());
- assertEquals(true, res.at("/query/wrap/flags/0").isMissingNode());
- assertEquals("orth", res.at("/query/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("deutscher", res.at("/query/wrap/key").asText());
+ assertEquals(true, res.at("/query/wrap/flags/0").isMissingNode());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
query = "[orth=deutscher/i][orth=Bundestag]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
operands = Lists.newArrayList(res.at("/query/operands").elements());
- assertEquals("koral:token", operands.get(0).at("/@type").asText());
- assertEquals("deutscher", operands.get(0).at("/wrap/key").asText());
- assertEquals("orth", operands.get(0).at("/wrap/layer").asText());
- assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
- assertEquals("flags:caseInsensitive", operands.get(0).at("/wrap/flags/0").asText());
- assertEquals("koral:token", operands.get(1).at("/@type").asText());
- assertEquals("Bundestag", operands.get(1).at("/wrap/key").asText());
- assertEquals("orth", operands.get(1).at("/wrap/layer").asText());
- assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
- assertEquals(true, operands.get(1).at("/wrap/flags/0").isMissingNode());
+ assertEquals("koral:token", operands.get(0).at("/@type").asText());
+ assertEquals("deutscher", operands.get(0).at("/wrap/key").asText());
+ assertEquals("orth", operands.get(0).at("/wrap/layer").asText());
+ assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
+ assertEquals("flags:caseInsensitive",
+ operands.get(0).at("/wrap/flags/0").asText());
+ assertEquals("koral:token", operands.get(1).at("/@type").asText());
+ assertEquals("Bundestag", operands.get(1).at("/wrap/key").asText());
+ assertEquals("orth", operands.get(1).at("/wrap/layer").asText());
+ assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
+ assertEquals(true, operands.get(1).at("/wrap/flags/0").isMissingNode());
query = "deutscher/i Bundestag";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
operands = Lists.newArrayList(res.at("/query/operands").elements());
- assertEquals("koral:token", operands.get(0).at("/@type").asText());
- assertEquals("deutscher", operands.get(0).at("/wrap/key").asText());
- assertEquals("orth", operands.get(0).at("/wrap/layer").asText());
- assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
- assertEquals("flags:caseInsensitive", operands.get(0).at("/wrap/flags/0").asText());
- assertEquals("koral:token", operands.get(1).at("/@type").asText());
- assertEquals("Bundestag", operands.get(1).at("/wrap/key").asText());
- assertEquals("orth", operands.get(1).at("/wrap/layer").asText());
- assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
- assertEquals(true, operands.get(1).at("/wrap/flags:caseInsensitive").isMissingNode());
+ assertEquals("koral:token", operands.get(0).at("/@type").asText());
+ assertEquals("deutscher", operands.get(0).at("/wrap/key").asText());
+ assertEquals("orth", operands.get(0).at("/wrap/layer").asText());
+ assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
+ assertEquals("flags:caseInsensitive",
+ operands.get(0).at("/wrap/flags/0").asText());
+ assertEquals("koral:token", operands.get(1).at("/@type").asText());
+ assertEquals("Bundestag", operands.get(1).at("/wrap/key").asText());
+ assertEquals("orth", operands.get(1).at("/wrap/layer").asText());
+ assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
+ assertEquals(true, operands.get(1).at("/wrap/flags:caseInsensitive")
+ .isMissingNode());
}
+
@Test
- public void testSpans() throws JsonProcessingException, IOException {
+ public void testSpans () throws JsonProcessingException, IOException {
query = "<s>";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("s", res.at("/query/wrap/key").asText());
-
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("s", res.at("/query/wrap/key").asText());
+
query = "<\".*\">";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals(".*", res.at("/query/wrap/key").asText());
- assertEquals("type:regex", res.at("/query/wrap/type").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals(".*", res.at("/query/wrap/key").asText());
+ assertEquals("type:regex", res.at("/query/wrap/type").asText());
query = "<vp>";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("vp", res.at("/query/wrap/key").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("vp", res.at("/query/wrap/key").asText());
query = "<cnx/c=vp>";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("vp", res.at("/query/wrap/key").asText());
- assertEquals("cnx", res.at("/query/wrap/foundry").asText());
- assertEquals("c", res.at("/query/wrap/layer").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("vp", res.at("/query/wrap/key").asText());
+ assertEquals("cnx", res.at("/query/wrap/foundry").asText());
+ assertEquals("c", res.at("/query/wrap/layer").asText());
query = "<cnx/c!=vp>";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("vp", res.at("/query/wrap/key").asText());
- assertEquals("cnx", res.at("/query/wrap/foundry").asText());
- assertEquals("c", res.at("/query/wrap/layer").asText());
- assertEquals("match:ne", res.at("/query/wrap/match").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("vp", res.at("/query/wrap/key").asText());
+ assertEquals("cnx", res.at("/query/wrap/foundry").asText());
+ assertEquals("c", res.at("/query/wrap/layer").asText());
+ assertEquals("match:ne", res.at("/query/wrap/match").asText());
query = "<cnx/c!=vp class!=header>";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("vp", res.at("/query/wrap/key").asText());
- assertEquals("cnx", res.at("/query/wrap/foundry").asText());
- assertEquals("c", res.at("/query/wrap/layer").asText());
- assertEquals("match:ne", res.at("/query/wrap/match").asText());
- assertEquals("class", res.at("/query/attr/key").asText());
- assertEquals("header", res.at("/query/attr/value").asText());
- assertEquals("match:ne", res.at("/query/attr/match").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("vp", res.at("/query/wrap/key").asText());
+ assertEquals("cnx", res.at("/query/wrap/foundry").asText());
+ assertEquals("c", res.at("/query/wrap/layer").asText());
+ assertEquals("match:ne", res.at("/query/wrap/match").asText());
+ assertEquals("class", res.at("/query/attr/key").asText());
+ assertEquals("header", res.at("/query/attr/value").asText());
+ assertEquals("match:ne", res.at("/query/attr/match").asText());
query = "<cnx/c!=vp !(class!=header)>";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("vp", res.at("/query/wrap/key").asText());
- assertEquals("cnx", res.at("/query/wrap/foundry").asText());
- assertEquals("c", res.at("/query/wrap/layer").asText());
- assertEquals("match:ne", res.at("/query/wrap/match").asText());
- assertEquals("class", res.at("/query/attr/key").asText());
- assertEquals("header", res.at("/query/attr/value").asText());
- assertEquals("match:eq", res.at("/query/attr/match").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("vp", res.at("/query/wrap/key").asText());
+ assertEquals("cnx", res.at("/query/wrap/foundry").asText());
+ assertEquals("c", res.at("/query/wrap/layer").asText());
+ assertEquals("match:ne", res.at("/query/wrap/match").asText());
+ assertEquals("class", res.at("/query/attr/key").asText());
+ assertEquals("header", res.at("/query/attr/value").asText());
+ assertEquals("match:eq", res.at("/query/attr/match").asText());
query = "<cnx/c!=vp !(class=header & id=7)>";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/@type").asText());
- assertEquals("vp", res.at("/query/wrap/key").asText());
- assertEquals("cnx", res.at("/query/wrap/foundry").asText());
- assertEquals("c", res.at("/query/wrap/layer").asText());
- assertEquals("match:ne", res.at("/query/wrap/match").asText());
- assertEquals("koral:termGroup", res.at("/query/attr/@type").asText());
- assertEquals("relation:and", res.at("/query/attr/relation").asText());
- operands = Lists.newArrayList( res.at("/query/attr/operands").elements());
- assertEquals("koral:term", operands.get(0).at("/@type").asText());
- assertEquals("class", operands.get(0).at("/key").asText());
- assertEquals("header", operands.get(0).at("/value").asText());
- assertEquals("match:ne", operands.get(0).at("/match").asText());
- assertEquals("koral:term", operands.get(1).at("/@type").asText());
- assertEquals("id", operands.get(1).at("/key").asText());
- assertEquals(7, operands.get(1).at("/value").asInt());
- assertEquals("match:ne", operands.get(1).at("/match").asText());
+ assertEquals("koral:span", res.at("/query/@type").asText());
+ assertEquals("vp", res.at("/query/wrap/key").asText());
+ assertEquals("cnx", res.at("/query/wrap/foundry").asText());
+ assertEquals("c", res.at("/query/wrap/layer").asText());
+ assertEquals("match:ne", res.at("/query/wrap/match").asText());
+ assertEquals("koral:termGroup", res.at("/query/attr/@type").asText());
+ assertEquals("relation:and", res.at("/query/attr/relation").asText());
+ operands = Lists
+ .newArrayList(res.at("/query/attr/operands").elements());
+ assertEquals("koral:term", operands.get(0).at("/@type").asText());
+ assertEquals("class", operands.get(0).at("/key").asText());
+ assertEquals("header", operands.get(0).at("/value").asText());
+ assertEquals("match:ne", operands.get(0).at("/match").asText());
+ assertEquals("koral:term", operands.get(1).at("/@type").asText());
+ assertEquals("id", operands.get(1).at("/key").asText());
+ assertEquals(7, operands.get(1).at("/value").asInt());
+ assertEquals("match:ne", operands.get(1).at("/match").asText());
}
+
@Test
- public void testDistances() throws JsonProcessingException, IOException {
+ public void testDistances () throws JsonProcessingException, IOException {
query = "[base=der][][base=Mann]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("true", res.at("/query/inOrder").asText());
- assertEquals("koral:distance", res.at("/query/distances").elements().next().at("/@type").asText());
- assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
- assertEquals("koral:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
- assertEquals(1, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
- assertEquals(1, res.at("/query/distances").elements().next().at("/boundary/max").asInt());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("true", res.at("/query/inOrder").asText());
+ assertEquals("koral:distance", res.at("/query/distances").elements()
+ .next().at("/@type").asText());
+ assertEquals("w",
+ res.at("/query/distances").elements().next().at("/key")
+ .asText());
+ assertEquals("koral:boundary", res.at("/query/distances").elements()
+ .next().at("/boundary/@type").asText());
+ assertEquals(1,
+ res.at("/query/distances").elements().next()
+ .at("/boundary/min").asInt());
+ assertEquals(1,
+ res.at("/query/distances").elements().next()
+ .at("/boundary/max").asInt());
operands = Lists.newArrayList(res.at("/query/operands").elements());
- assertEquals("koral:token", operands.get(0).at("/@type").asText());
- assertEquals("der", operands.get(0).at("/wrap/key").asText());
- assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
- assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
- assertEquals("koral:token", operands.get(1).at("/@type").asText());
- assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
- assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
- assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
+ assertEquals("koral:token", operands.get(0).at("/@type").asText());
+ assertEquals("der", operands.get(0).at("/wrap/key").asText());
+ assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
+ assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
+ assertEquals("koral:token", operands.get(1).at("/@type").asText());
+ assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
+ assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
+ assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
query = "[base=der][][][base=Mann]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("true", res.at("/query/inOrder").asText());
- assertEquals("koral:distance", res.at("/query/distances").elements().next().at("/@type").asText());
- assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
- assertEquals("koral:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
- assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
- assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/max").asInt());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("true", res.at("/query/inOrder").asText());
+ assertEquals("koral:distance", res.at("/query/distances").elements()
+ .next().at("/@type").asText());
+ assertEquals("w",
+ res.at("/query/distances").elements().next().at("/key")
+ .asText());
+ assertEquals("koral:boundary", res.at("/query/distances").elements()
+ .next().at("/boundary/@type").asText());
+ assertEquals(2,
+ res.at("/query/distances").elements().next()
+ .at("/boundary/min").asInt());
+ assertEquals(2,
+ res.at("/query/distances").elements().next()
+ .at("/boundary/max").asInt());
operands = Lists.newArrayList(res.at("/query/operands").elements());
- assertEquals("koral:token", operands.get(0).at("/@type").asText());
- assertEquals("der", operands.get(0).at("/wrap/key").asText());
- assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
- assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
- assertEquals("koral:token", operands.get(1).at("/@type").asText());
- assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
- assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
- assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
+ assertEquals("koral:token", operands.get(0).at("/@type").asText());
+ assertEquals("der", operands.get(0).at("/wrap/key").asText());
+ assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
+ assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
+ assertEquals("koral:token", operands.get(1).at("/@type").asText());
+ assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
+ assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
+ assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
query = "[base=der][][]?[base=Mann]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("true", res.at("/query/inOrder").asText());
- assertEquals("koral:distance", res.at("/query/distances").elements().next().at("/@type").asText());
- assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
- assertEquals("koral:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
- assertEquals(1, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
- assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/max").asInt());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("true", res.at("/query/inOrder").asText());
+ assertEquals("koral:distance", res.at("/query/distances").elements()
+ .next().at("/@type").asText());
+ assertEquals("w",
+ res.at("/query/distances").elements().next().at("/key")
+ .asText());
+ assertEquals("koral:boundary", res.at("/query/distances").elements()
+ .next().at("/boundary/@type").asText());
+ assertEquals(1,
+ res.at("/query/distances").elements().next()
+ .at("/boundary/min").asInt());
+ assertEquals(2,
+ res.at("/query/distances").elements().next()
+ .at("/boundary/max").asInt());
operands = Lists.newArrayList(res.at("/query/operands").elements());
- assertEquals("koral:token", operands.get(0).at("/@type").asText());
- assertEquals("der", operands.get(0).at("/wrap/key").asText());
- assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
- assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
- assertEquals("koral:token", operands.get(1).at("/@type").asText());
- assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
- assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
- assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
+ assertEquals("koral:token", operands.get(0).at("/@type").asText());
+ assertEquals("der", operands.get(0).at("/wrap/key").asText());
+ assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
+ assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
+ assertEquals("koral:token", operands.get(1).at("/@type").asText());
+ assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
+ assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
+ assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
query = "[base=der][]+[base=Mann]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("true", res.at("/query/inOrder").asText());
- assertEquals("koral:distance", res.at("/query/distances").elements().next().at("/@type").asText());
- assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
- assertEquals("koral:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
- assertEquals(1, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
- assertEquals(true, res.at("/query/distances").elements().next().at("/boundary/max").isMissingNode());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("true", res.at("/query/inOrder").asText());
+ assertEquals("koral:distance", res.at("/query/distances").elements()
+ .next().at("/@type").asText());
+ assertEquals("w",
+ res.at("/query/distances").elements().next().at("/key")
+ .asText());
+ assertEquals("koral:boundary", res.at("/query/distances").elements()
+ .next().at("/boundary/@type").asText());
+ assertEquals(1,
+ res.at("/query/distances").elements().next()
+ .at("/boundary/min").asInt());
+ assertEquals(true,
+ res.at("/query/distances").elements().next()
+ .at("/boundary/max").isMissingNode());
operands = Lists.newArrayList(res.at("/query/operands").elements());
- assertEquals("koral:token", operands.get(0).at("/@type").asText());
- assertEquals("der", operands.get(0).at("/wrap/key").asText());
- assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
- assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
- assertEquals("koral:token", operands.get(1).at("/@type").asText());
- assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
- assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
- assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
+ assertEquals("koral:token", operands.get(0).at("/@type").asText());
+ assertEquals("der", operands.get(0).at("/wrap/key").asText());
+ assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
+ assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
+ assertEquals("koral:token", operands.get(1).at("/@type").asText());
+ assertEquals("Mann", operands.get(1).at("/wrap/key").asText());
+ assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
+ assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
query = "[base=der][]*[base=Mann]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("true", res.at("/query/inOrder").asText());
- assertEquals("koral:distance", res.at("/query/distances").elements().next().at("/@type").asText());
- assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
- assertEquals("koral:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
- assertEquals(0, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
- assertEquals(true, res.at("/query/distances").elements().next().at("/boundary/max").isMissingNode());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("true", res.at("/query/inOrder").asText());
+ assertEquals("koral:distance", res.at("/query/distances").elements()
+ .next().at("/@type").asText());
+ assertEquals("w",
+ res.at("/query/distances").elements().next().at("/key")
+ .asText());
+ assertEquals("koral:boundary", res.at("/query/distances").elements()
+ .next().at("/boundary/@type").asText());
+ assertEquals(0,
+ res.at("/query/distances").elements().next()
+ .at("/boundary/min").asInt());
+ assertEquals(true,
+ res.at("/query/distances").elements().next()
+ .at("/boundary/max").isMissingNode());
query = "[base=der][]{2,5}[base=Mann][]?[][base=Frau]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("true", res.at("/query/inOrder").asText());
- assertEquals("koral:distance", res.at("/query/distances").elements().next().at("/@type").asText());
- assertEquals("w", res.at("/query/distances").elements().next().at("/key").asText());
- assertEquals("koral:boundary", res.at("/query/distances").elements().next().at("/boundary/@type").asText());
- assertEquals(2, res.at("/query/distances").elements().next().at("/boundary/min").asInt());
- assertEquals(5, res.at("/query/distances").elements().next().at("/boundary/max").asInt());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("true", res.at("/query/inOrder").asText());
+ assertEquals("koral:distance", res.at("/query/distances").elements()
+ .next().at("/@type").asText());
+ assertEquals("w",
+ res.at("/query/distances").elements().next().at("/key")
+ .asText());
+ assertEquals("koral:boundary", res.at("/query/distances").elements()
+ .next().at("/boundary/@type").asText());
+ assertEquals(2,
+ res.at("/query/distances").elements().next()
+ .at("/boundary/min").asInt());
+ assertEquals(5,
+ res.at("/query/distances").elements().next()
+ .at("/boundary/max").asInt());
operands = Lists.newArrayList(res.at("/query/operands").elements());
- assertEquals("koral:token", operands.get(0).at("/@type").asText());
- assertEquals("der", operands.get(0).at("/wrap/key").asText());
- assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
- assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
- assertEquals("koral:group", operands.get(1).at("/@type").asText());
- assertEquals("operation:sequence", operands.get(1).at("/operation").asText());
- assertEquals("koral:distance", operands.get(1).get("distances").elements().next().at("/@type").asText());
- assertEquals("w", operands.get(1).get("distances").elements().next().at("/key").asText());
- assertEquals("koral:boundary", operands.get(1).get("distances").elements().next().at("/boundary/@type").asText());
- assertEquals(1, operands.get(1).get("distances").elements().next().at("/boundary/min").asInt());
- assertEquals(2, operands.get(1).get("distances").elements().next().at("/boundary/max").asInt());
- operands = Lists.newArrayList(operands.get(1).get("operands").elements());
- assertEquals("Mann", operands.get(0).at("/wrap/key").asText());
- assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
- assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
- assertEquals("Frau", operands.get(1).at("/wrap/key").asText());
- assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
- assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
+ assertEquals("koral:token", operands.get(0).at("/@type").asText());
+ assertEquals("der", operands.get(0).at("/wrap/key").asText());
+ assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
+ assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
+ assertEquals("koral:group", operands.get(1).at("/@type").asText());
+ assertEquals("operation:sequence", operands.get(1).at("/operation")
+ .asText());
+ assertEquals("koral:distance", operands.get(1).get("distances")
+ .elements().next().at("/@type").asText());
+ assertEquals("w", operands.get(1).get("distances").elements().next()
+ .at("/key").asText());
+ assertEquals("koral:boundary", operands.get(1).get("distances")
+ .elements().next().at("/boundary/@type").asText());
+ assertEquals(
+ 1,
+ operands.get(1).get("distances").elements().next()
+ .at("/boundary/min").asInt());
+ assertEquals(
+ 2,
+ operands.get(1).get("distances").elements().next()
+ .at("/boundary/max").asInt());
+ operands = Lists.newArrayList(operands.get(1).get("operands")
+ .elements());
+ assertEquals("Mann", operands.get(0).at("/wrap/key").asText());
+ assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
+ assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
+ assertEquals("Frau", operands.get(1).at("/wrap/key").asText());
+ assertEquals("lemma", operands.get(1).at("/wrap/layer").asText());
+ assertEquals("match:eq", operands.get(1).at("/wrap/match").asText());
query = "[base=geht][base=der][]*contains(<s>,<np>)";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals(true, res.at("/query/inOrder").isMissingNode());
- assertEquals(true, res.at("/query/distances").isMissingNode());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals(true, res.at("/query/inOrder").isMissingNode());
+ assertEquals(true, res.at("/query/distances").isMissingNode());
operands = Lists.newArrayList(res.at("/query/operands").elements());
- assertEquals("koral:token", operands.get(0).at("/@type").asText());
- assertEquals("geht", operands.get(0).at("/wrap/key").asText());
- assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
- assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
- assertEquals("koral:group", operands.get(1).at("/@type").asText());
- assertEquals("operation:sequence", operands.get(1).at("/operation").asText());
- assertEquals("koral:distance", operands.get(1).get("distances").elements().next().at("/@type").asText());
- assertEquals("w", operands.get(1).get("distances").elements().next().at("/key").asText());
- assertEquals("koral:boundary", operands.get(1).get("distances").elements().next().at("/boundary/@type").asText());
- assertEquals(0, operands.get(1).get("distances").elements().next().at("/boundary/min").asInt());
- assertEquals(true, operands.get(1).get("distances").elements().next().at("/boundary/max").isMissingNode());
- operands = Lists.newArrayList(operands.get(1).get("operands").elements());
- assertEquals("der", operands.get(0).at("/wrap/key").asText());
- assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
- assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
- assertEquals("koral:group", operands.get(1).at("/@type").asText());
- assertEquals("operation:position", operands.get(1).at("/operation").asText());
+ assertEquals("koral:token", operands.get(0).at("/@type").asText());
+ assertEquals("geht", operands.get(0).at("/wrap/key").asText());
+ assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
+ assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
+ assertEquals("koral:group", operands.get(1).at("/@type").asText());
+ assertEquals("operation:sequence", operands.get(1).at("/operation")
+ .asText());
+ assertEquals("koral:distance", operands.get(1).get("distances")
+ .elements().next().at("/@type").asText());
+ assertEquals("w", operands.get(1).get("distances").elements().next()
+ .at("/key").asText());
+ assertEquals("koral:boundary", operands.get(1).get("distances")
+ .elements().next().at("/boundary/@type").asText());
+ assertEquals(
+ 0,
+ operands.get(1).get("distances").elements().next()
+ .at("/boundary/min").asInt());
+ assertEquals(true, operands.get(1).get("distances").elements().next()
+ .at("/boundary/max").isMissingNode());
+ operands = Lists.newArrayList(operands.get(1).get("operands")
+ .elements());
+ assertEquals("der", operands.get(0).at("/wrap/key").asText());
+ assertEquals("lemma", operands.get(0).at("/wrap/layer").asText());
+ assertEquals("match:eq", operands.get(0).at("/wrap/match").asText());
+ assertEquals("koral:group", operands.get(1).at("/@type").asText());
+ assertEquals("operation:position", operands.get(1).at("/operation")
+ .asText());
}
+
@Test
- public void testDistancesWithClass() throws JsonProcessingException, IOException {
+ public void testDistancesWithClass () throws JsonProcessingException,
+ IOException {
query = "[base=der]{[]}[base=Mann]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals(true, res.at("/query/inOrder").isMissingNode());
- assertEquals(true, res.at("/query/distances").isMissingNode());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals(true, res.at("/query/inOrder").isMissingNode());
+ assertEquals(true, res.at("/query/distances").isMissingNode());
operands = Lists.newArrayList(res.at("/query/operands").elements());
- assertEquals("der", operands.get(0).at("/wrap/key").asText());
- assertEquals("Mann", operands.get(2).at("/wrap/key").asText());
- assertEquals("koral:group", operands.get(1).at("/@type").asText());
- assertEquals("operation:class", operands.get(1).at("/operation").asText());
- assertEquals(1, operands.get(1).at("/classOut").asInt());
- operands = Lists.newArrayList(operands.get(1).at("/operands").elements());
- assertEquals("koral:token", operands.get(0).at("/@type").asText());
- assertEquals(true, operands.get(0).at("/wrap").isMissingNode());
- assertEquals(1, res.at("/meta/highlight/0").asInt());
+ assertEquals("der", operands.get(0).at("/wrap/key").asText());
+ assertEquals("Mann", operands.get(2).at("/wrap/key").asText());
+ assertEquals("koral:group", operands.get(1).at("/@type").asText());
+ assertEquals("operation:class", operands.get(1).at("/operation")
+ .asText());
+ assertEquals(1, operands.get(1).at("/classOut").asInt());
+ operands = Lists.newArrayList(operands.get(1).at("/operands")
+ .elements());
+ assertEquals("koral:token", operands.get(0).at("/@type").asText());
+ assertEquals(true, operands.get(0).at("/wrap").isMissingNode());
+ assertEquals(1, res.at("/meta/highlight/0").asInt());
query = "[base=der]{2:[]}[base=Mann]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
operands = Lists.newArrayList(res.at("/query/operands").elements());
- assertEquals("operation:class", operands.get(1).at("/operation").asText());
- assertEquals(2, operands.get(1).at("/classOut").asInt());
- assertEquals(2, res.at("/meta/highlight/0").asInt());
+ assertEquals("operation:class", operands.get(1).at("/operation")
+ .asText());
+ assertEquals(2, operands.get(1).at("/classOut").asInt());
+ assertEquals(2, res.at("/meta/highlight/0").asInt());
query = "[base=der]{3:{2:[]}}";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
operands = Lists.newArrayList(res.at("/query/operands").elements());
- assertEquals("operation:class", operands.get(1).at("/operation").asText());
- assertEquals(3, operands.get(1).at("/classOut").asInt());
- assertEquals(3, res.at("/meta/highlight/0").asInt());
- assertEquals("operation:class", operands.get(1).at("/operands/0/operation").asText());
- assertEquals(2, operands.get(1).at("/operands/0/classOut").asInt());
- assertEquals(3, res.at("/meta/highlight/0").asInt());
- assertEquals(2, res.at("/meta/highlight/1").asInt());
+ assertEquals("operation:class", operands.get(1).at("/operation")
+ .asText());
+ assertEquals(3, operands.get(1).at("/classOut").asInt());
+ assertEquals(3, res.at("/meta/highlight/0").asInt());
+ assertEquals("operation:class",
+ operands.get(1).at("/operands/0/operation").asText());
+ assertEquals(2, operands.get(1).at("/operands/0/classOut").asInt());
+ assertEquals(3, res.at("/meta/highlight/0").asInt());
+ assertEquals(2, res.at("/meta/highlight/1").asInt());
query = "{1:[]}[base=der][base=Mann]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
operands = Lists.newArrayList(res.at("/query/operands").elements());
- assertEquals("operation:class", operands.get(0).at("/operation").asText());
- assertEquals(1, operands.get(0).at("/classOut").asInt());
- assertEquals(1, res.at("/meta/highlight/0").asInt());
+ assertEquals("operation:class", operands.get(0).at("/operation")
+ .asText());
+ assertEquals(1, operands.get(0).at("/classOut").asInt());
+ assertEquals(1, res.at("/meta/highlight/0").asInt());
query = "{1:{2:der} {3:[]} Mann}";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
operands = Lists.newArrayList(res.at("/query/operands").elements());
- assertEquals(1, operands.size()); // class operation may only have one operand (the sequence)
- operands = Lists.newArrayList(operands.get(0).at("/operands").elements());
- assertEquals(3, operands.size()); // the sequence has three operands ("der", "[]" and "Mann")
- assertEquals(1, res.at("/meta/highlight/0").asInt());
- assertEquals(2, res.at("/meta/highlight/1").asInt());
- assertEquals(3, res.at("/meta/highlight/2").asInt());
+ assertEquals(1, operands.size()); // class operation may only have one operand (the sequence)
+ operands = Lists.newArrayList(operands.get(0).at("/operands")
+ .elements());
+ assertEquals(3, operands.size()); // the sequence has three operands ("der", "[]" and "Mann")
+ assertEquals(1, res.at("/meta/highlight/0").asInt());
+ assertEquals(2, res.at("/meta/highlight/1").asInt());
+ assertEquals(3, res.at("/meta/highlight/2").asInt());
}
+
@Test
- public void testEmptyTokens() throws JsonProcessingException, IOException {
+ public void testEmptyTokens () throws JsonProcessingException, IOException {
query = "[]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals(true, res.at("/query/key").isMissingNode());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals(true, res.at("/query/key").isMissingNode());
query = "contains(<s>, [])";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:position", res.at("/query/operation").asText());
- assertEquals("frames:isAround", res.at("/query/frames/0").asText());
- assertEquals(true, res.at("/query/frames/1").isMissingNode());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
- assertEquals(true, res.at("/query/operands/1/key").isMissingNode());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:position", res.at("/query/operation").asText());
+ assertEquals("frames:isAround", res.at("/query/frames/0").asText());
+ assertEquals(true, res.at("/query/frames/1").isMissingNode());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
+ assertEquals(true, res.at("/query/operands/1/key").isMissingNode());
query = "contains(<s>, []{3})";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:repetition",res.at("/query/operands/1/operation").asText());
- assertEquals("koral:token", res.at("/query/operands/1/operands/0/@type").asText());
- assertEquals(true, res.at("/query/operands/1/operands/0/key").isMissingNode());
+ assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:repetition",
+ res.at("/query/operands/1/operation").asText());
+ assertEquals("koral:token", res
+ .at("/query/operands/1/operands/0/@type").asText());
+ assertEquals(true, res.at("/query/operands/1/operands/0/key")
+ .isMissingNode());
query = "contains(<s>, {1:[]{3}})";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/1/operation").asText());
- assertEquals("operation:repetition",res.at("/query/operands/1/operands/0/operation").asText());
- assertEquals("koral:token", res.at("/query/operands/1/operands/0/operands/0/@type").asText());
- assertEquals(true, res.at("/query/operands/1/operands/0/operands/0/key").isMissingNode());
+ assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:class", res.at("/query/operands/1/operation")
+ .asText());
+ assertEquals("operation:repetition",
+ res.at("/query/operands/1/operands/0/operation").asText());
+ assertEquals("koral:token",
+ res.at("/query/operands/1/operands/0/operands/0/@type")
+ .asText());
+ assertEquals(true, res
+ .at("/query/operands/1/operands/0/operands/0/key")
+ .isMissingNode());
}
+
@Test
- public void testLeadingTrailingEmptyTokens() throws JsonProcessingException, IOException {
+ public void testLeadingTrailingEmptyTokens ()
+ throws JsonProcessingException, IOException {
query = "[][base=Mann]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
operands = Lists.newArrayList(res.at("/query/operands").elements());
- assertEquals("koral:token", operands.get(0).at("/@type").asText());
- assertEquals(true, operands.get(0).at("/key").isMissingNode());
+ assertEquals("koral:token", operands.get(0).at("/@type").asText());
+ assertEquals(true, operands.get(0).at("/key").isMissingNode());
query = "[][][base=Mann]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
operands = Lists.newArrayList(res.at("/query/operands").elements());
- assertEquals("koral:group", operands.get(0).at("/@type").asText());
- assertEquals("operation:repetition",operands.get(0).at("/operation").asText());
- assertEquals(2, operands.get(0).at("/boundary/min").asInt());
- assertEquals(2, operands.get(0).at("/boundary/max").asInt());
- operands = Lists.newArrayList(operands.get(0).at("/operands").elements());
- assertEquals("koral:token", operands.get(0).at("/@type").asText());
- assertEquals(true, operands.get(0).at("/key").isMissingNode());
+ assertEquals("koral:group", operands.get(0).at("/@type").asText());
+ assertEquals("operation:repetition", operands.get(0).at("/operation")
+ .asText());
+ assertEquals(2, operands.get(0).at("/boundary/min").asInt());
+ assertEquals(2, operands.get(0).at("/boundary/max").asInt());
+ operands = Lists.newArrayList(operands.get(0).at("/operands")
+ .elements());
+ assertEquals("koral:token", operands.get(0).at("/@type").asText());
+ assertEquals(true, operands.get(0).at("/key").isMissingNode());
query = "startswith(<s>, [][base=Mann])";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
operands = Lists.newArrayList(res.at("/query/operands"));
operands = Lists.newArrayList(operands.get(1).at("/operands"));
- assertEquals("koral:token", operands.get(0).at("/@type").asText());
- assertEquals(true, operands.get(0).at("/key").isMissingNode());
+ assertEquals("koral:token", operands.get(0).at("/@type").asText());
+ assertEquals(true, operands.get(0).at("/key").isMissingNode());
}
+
@Test
- public void testRepetition() throws JsonProcessingException, IOException {
+ public void testRepetition () throws JsonProcessingException, IOException {
query = "der{3}";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:repetition", res.at("/query/operation").asText());
- assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals(3, res.at("/query/boundary/min").asInt());
- assertEquals(3, res.at("/query/boundary/max").asInt());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:repetition", res.at("/query/operation")
+ .asText());
+ assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals(3, res.at("/query/boundary/min").asInt());
+ assertEquals(3, res.at("/query/boundary/max").asInt());
query = "der{,3}";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(0, res.at("/query/boundary/min").asInt());
- assertEquals(3, res.at("/query/boundary/max").asInt());
+ assertEquals(0, res.at("/query/boundary/min").asInt());
+ assertEquals(3, res.at("/query/boundary/max").asInt());
query = "der{3,}";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(3, res.at("/query/boundary/min").asInt());
- assertEquals(true, res.at("/query/boundary/max").isMissingNode());
+ assertEquals(3, res.at("/query/boundary/min").asInt());
+ assertEquals(true, res.at("/query/boundary/max").isMissingNode());
query = "der{3,7}";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(3, res.at("/query/boundary/min").asInt());
- assertEquals(7, res.at("/query/boundary/max").asInt());
+ assertEquals(3, res.at("/query/boundary/min").asInt());
+ assertEquals(7, res.at("/query/boundary/max").asInt());
query = "der*";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(0, res.at("/query/boundary/min").asInt());
- assertEquals(true, res.at("/query/boundary/max").isMissingNode());
+ assertEquals(0, res.at("/query/boundary/min").asInt());
+ assertEquals(true, res.at("/query/boundary/max").isMissingNode());
query = "der+";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(1, res.at("/query/boundary/min").asInt());
- assertEquals(true, res.at("/query/boundary/max").isMissingNode());
+ assertEquals(1, res.at("/query/boundary/min").asInt());
+ assertEquals(true, res.at("/query/boundary/max").isMissingNode());
};
+
@Test
- public void testGroupRepetition() throws JsonProcessingException, IOException {
+ public void testGroupRepetition () throws JsonProcessingException,
+ IOException {
query = "contains(<s>, (der){3})";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:position", res.at("/query/operation").asText());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:repetition",res.at("/query/operands/1/operation").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:position", res.at("/query/operation").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:repetition",
+ res.at("/query/operands/1/operation").asText());
query = "contains(<s>, (der){3,})";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(3, res.at("/query/operands/1/boundary/min").asInt());
- assertEquals(true, res.at("/query/operands/1/boundary/max").isMissingNode());
+ assertEquals(3, res.at("/query/operands/1/boundary/min").asInt());
+ assertEquals(true, res.at("/query/operands/1/boundary/max")
+ .isMissingNode());
query = "contains(<s>, (der){,3})";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(0, res.at("/query/operands/1/boundary/min").asInt());
- assertEquals(3, res.at("/query/operands/1/boundary/max").asInt());
+ assertEquals(0, res.at("/query/operands/1/boundary/min").asInt());
+ assertEquals(3, res.at("/query/operands/1/boundary/max").asInt());
query = "contains(<s>, (der){3,7})";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(3, res.at("/query/operands/1/boundary/min").asInt());
- assertEquals(7, res.at("/query/operands/1/boundary/max").asInt());
+ assertEquals(3, res.at("/query/operands/1/boundary/min").asInt());
+ assertEquals(7, res.at("/query/operands/1/boundary/max").asInt());
query = "contains(<s>, (der)*)";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(0, res.at("/query/operands/1/boundary/min").asInt());
- assertEquals(true, res.at("/query/operands/1/boundary/max").isMissingNode());
+ assertEquals(0, res.at("/query/operands/1/boundary/min").asInt());
+ assertEquals(true, res.at("/query/operands/1/boundary/max")
+ .isMissingNode());
};
+
@Test
- public void testPositions() throws JsonProcessingException, IOException {
+ public void testPositions () throws JsonProcessingException, IOException {
query = "contains(<s>, der)";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:position", res.at("/query/operation").asText());
- assertEquals("frames:isAround", res.at("/query/frames/0").asText());
- assertEquals(true, res.at("/query/frames/1").isMissingNode());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:position", res.at("/query/operation").asText());
+ assertEquals("frames:isAround", res.at("/query/frames/0").asText());
+ assertEquals(true, res.at("/query/frames/1").isMissingNode());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
query = "contains(<s>,<np>)";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("np", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("np", res.at("/query/operands/1/wrap/key").asText());
query = "contains(<s>,[orth=der][orth=Mann])";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:position", res.at("/query/operation").asText());
- assertEquals("frames:isAround", res.at("/query/frames/0").asText());
- assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operands/1/operation").asText());
- assertEquals("der", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals("Mann", res.at("/query/operands/1/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:position", res.at("/query/operation").asText());
+ assertEquals("frames:isAround", res.at("/query/frames/0").asText());
+ assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:sequence", res
+ .at("/query/operands/1/operation").asText());
+ assertEquals("der", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("Mann", res.at("/query/operands/1/operands/1/wrap/key")
+ .asText());
query = "contains(<s>,[orth=der][orth=Mann]*)";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:position", res.at("/query/operation").asText());
- assertEquals("frames:isAround", res.at("/query/frames/0").asText());
- assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operands/1/operation").asText());
- assertEquals("der", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals("operation:repetition", res.at("/query/operands/1/operands/1/operation").asText());
- assertEquals(0, res.at("/query/operands/1/operands/1/boundary/min").asInt());
- assertEquals(true, res.at("/query/operands/1/operands/1/boundary/max").isMissingNode());
- assertEquals("Mann", res.at("/query/operands/1/operands/1/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:position", res.at("/query/operation").asText());
+ assertEquals("frames:isAround", res.at("/query/frames/0").asText());
+ assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:sequence", res
+ .at("/query/operands/1/operation").asText());
+ assertEquals("der", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("operation:repetition",
+ res.at("/query/operands/1/operands/1/operation").asText());
+ assertEquals(0, res.at("/query/operands/1/operands/1/boundary/min")
+ .asInt());
+ assertEquals(true, res.at("/query/operands/1/operands/1/boundary/max")
+ .isMissingNode());
+ assertEquals("Mann",
+ res.at("/query/operands/1/operands/1/operands/0/wrap/key")
+ .asText());
query = "contains(<s>,startswith(<np>,<pp>))";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
- assertEquals("frames:startsWith", res.at("/query/operands/1/frames/0").asText());
- assertEquals("operation:position", res.at("/query/operands/1/operation").asText());
- assertEquals("np", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals("pp", res.at("/query/operands/1/operands/1/wrap/key").asText());
+ assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("frames:startsWith", res.at("/query/operands/1/frames/0")
+ .asText());
+ assertEquals("operation:position", res
+ .at("/query/operands/1/operation").asText());
+ assertEquals("np", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("pp", res.at("/query/operands/1/operands/1/wrap/key")
+ .asText());
query = "[base=Auto]overlaps(<s>, der)";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/1/operation").asText());
- assertEquals("frames:overlapsLeft", res.at("/query/operands/1/frames/0").asText());
- assertEquals("frames:overlapsRight", res.at("/query/operands/1/frames/1").asText());
- assertEquals("koral:span", res.at("/query/operands/1/operands/0/@type").asText());
- assertEquals("s", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals("koral:token", res.at("/query/operands/1/operands/1/@type").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:position", res
+ .at("/query/operands/1/operation").asText());
+ assertEquals("frames:overlapsLeft", res
+ .at("/query/operands/1/frames/0").asText());
+ assertEquals("frames:overlapsRight",
+ res.at("/query/operands/1/frames/1").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/operands/0/@type")
+ .asText());
+ assertEquals("s", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("koral:token", res
+ .at("/query/operands/1/operands/1/@type").asText());
query = "[base=Auto] overlaps(<s>, der)";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:position", res.at("/query/operands/1/operation").asText());
- assertEquals("frames:overlapsLeft", res.at("/query/operands/1/frames/0").asText());
- assertEquals("frames:overlapsRight", res.at("/query/operands/1/frames/1").asText());
- assertEquals("koral:span", res.at("/query/operands/1/operands/0/@type").asText());
- assertEquals("s", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals("koral:token", res.at("/query/operands/1/operands/1/@type").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:position", res
+ .at("/query/operands/1/operation").asText());
+ assertEquals("frames:overlapsLeft", res
+ .at("/query/operands/1/frames/0").asText());
+ assertEquals("frames:overlapsRight",
+ res.at("/query/operands/1/frames/1").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/operands/0/@type")
+ .asText());
+ assertEquals("s", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("koral:token", res
+ .at("/query/operands/1/operands/1/@type").asText());
};
+
@Test
- public void testCoordinatedFields() throws JsonProcessingException, IOException {
+ public void testCoordinatedFields () throws JsonProcessingException,
+ IOException {
query = "[base=Mann&(cas=N|cas=A)]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("relation:and", res.at("/query/wrap/relation").asText());
- assertEquals("Mann", res.at("/query/wrap/operands/0/key").asText());
- assertEquals("lemma", res.at("/query/wrap/operands/0/layer").asText());
- assertEquals("koral:termGroup", res.at("/query/wrap/operands/1/@type").asText());
- assertEquals("relation:or", res.at("/query/wrap/operands/1/relation").asText());
- assertEquals("N", res.at("/query/wrap/operands/1/operands/0/key").asText());
- assertEquals("cas", res.at("/query/wrap/operands/1/operands/0/layer").asText());
- assertEquals("A", res.at("/query/wrap/operands/1/operands/1/key").asText());
- assertEquals("cas", res.at("/query/wrap/operands/1/operands/1/layer").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("relation:and", res.at("/query/wrap/relation").asText());
+ assertEquals("Mann", res.at("/query/wrap/operands/0/key").asText());
+ assertEquals("lemma", res.at("/query/wrap/operands/0/layer").asText());
+ assertEquals("koral:termGroup", res.at("/query/wrap/operands/1/@type")
+ .asText());
+ assertEquals("relation:or", res.at("/query/wrap/operands/1/relation")
+ .asText());
+ assertEquals("N", res.at("/query/wrap/operands/1/operands/0/key")
+ .asText());
+ assertEquals("cas", res.at("/query/wrap/operands/1/operands/0/layer")
+ .asText());
+ assertEquals("A", res.at("/query/wrap/operands/1/operands/1/key")
+ .asText());
+ assertEquals("cas", res.at("/query/wrap/operands/1/operands/1/layer")
+ .asText());
query = "[base=Mann&cas=N&gen=m]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("relation:and", res.at("/query/wrap/relation").asText());
- assertEquals("Mann", res.at("/query/wrap/operands/0/key").asText());
- assertEquals("lemma", res.at("/query/wrap/operands/0/layer").asText());
- assertEquals("koral:termGroup", res.at("/query/wrap/operands/1/@type").asText());
- assertEquals("relation:and", res.at("/query/wrap/operands/1/relation").asText());
- assertEquals("N", res.at("/query/wrap/operands/1/operands/0/key").asText());
- assertEquals("cas", res.at("/query/wrap/operands/1/operands/0/layer").asText());
- assertEquals("m", res.at("/query/wrap/operands/1/operands/1/key").asText());
- assertEquals("gen", res.at("/query/wrap/operands/1/operands/1/layer").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("relation:and", res.at("/query/wrap/relation").asText());
+ assertEquals("Mann", res.at("/query/wrap/operands/0/key").asText());
+ assertEquals("lemma", res.at("/query/wrap/operands/0/layer").asText());
+ assertEquals("koral:termGroup", res.at("/query/wrap/operands/1/@type")
+ .asText());
+ assertEquals("relation:and", res.at("/query/wrap/operands/1/relation")
+ .asText());
+ assertEquals("N", res.at("/query/wrap/operands/1/operands/0/key")
+ .asText());
+ assertEquals("cas", res.at("/query/wrap/operands/1/operands/0/layer")
+ .asText());
+ assertEquals("m", res.at("/query/wrap/operands/1/operands/1/key")
+ .asText());
+ assertEquals("gen", res.at("/query/wrap/operands/1/operands/1/layer")
+ .asText());
}
+
@Test
- public void testTokenSequence() throws JsonProcessingException, IOException {
+ public void testTokenSequence () throws JsonProcessingException,
+ IOException {
query = "[base=Mann][orth=Frau]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("lemma", res.at("/query/operands/0/wrap/layer").asText());
- assertEquals("Frau", res.at("/query/operands/1/wrap/key").asText());
- assertEquals("orth", res.at("/query/operands/1/wrap/layer").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("lemma", res.at("/query/operands/0/wrap/layer").asText());
+ assertEquals("Frau", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("orth", res.at("/query/operands/1/wrap/layer").asText());
query = "[base=Mann][orth=Frau][p=NN]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("NN", res.at("/query/operands/2/wrap/key").asText());
- assertEquals("p", res.at("/query/operands/2/wrap/layer").asText());
+ assertEquals("NN", res.at("/query/operands/2/wrap/key").asText());
+ assertEquals("p", res.at("/query/operands/2/wrap/layer").asText());
query = "[base=Mann][orth=Frau][p=NN][foo=bar]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("bar", res.at("/query/operands/3/wrap/key").asText());
- assertEquals("foo", res.at("/query/operands/3/wrap/layer").asText());
+ assertEquals("bar", res.at("/query/operands/3/wrap/key").asText());
+ assertEquals("foo", res.at("/query/operands/3/wrap/layer").asText());
}
+
@Test
- public void testDisjSegments() throws JsonProcessingException, IOException {
+ public void testDisjSegments () throws JsonProcessingException, IOException {
query = "[base=der]|[base=das]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:disjunction", res.at("/query/operation").asText());
- assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
- assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
- assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("lemma", res.at("/query/operands/0/wrap/layer").asText());
- assertEquals("das", res.at("/query/operands/1/wrap/key").asText());
- assertEquals("lemma", res.at("/query/operands/1/wrap/layer").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:disjunction", res.at("/query/operation")
+ .asText());
+ assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
+ assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("lemma", res.at("/query/operands/0/wrap/layer").asText());
+ assertEquals("das", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("lemma", res.at("/query/operands/1/wrap/layer").asText());
query = "([base=der]|[base=das])[base=Schild]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("Schild", res.at("/query/operands/1/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:disjunction", res.at("/query/operands/0/operation").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("Schild", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:disjunction",
+ res.at("/query/operands/0/operation").asText());
query = "[base=Schild]([base=der]|[base=das])";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("Schild", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:disjunction", res.at("/query/operands/1/operation").asText());
+ assertEquals("Schild", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:disjunction",
+ res.at("/query/operands/1/operation").asText());
query = "([orth=der][base=katze])|([orth=eine][base=baum])";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:disjunction", res.at("/query/operation").asText());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
- assertEquals("koral:token", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals("katze", res.at("/query/operands/0/operands/1/wrap/key").asText());
- assertEquals("eine", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals("baum", res.at("/query/operands/1/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:disjunction", res.at("/query/operation")
+ .asText());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:sequence", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("koral:token", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("katze", res.at("/query/operands/0/operands/1/wrap/key")
+ .asText());
+ assertEquals("eine", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("baum", res.at("/query/operands/1/operands/1/wrap/key")
+ .asText());
query = "[orth=der][base=katze]|[orth=eine][base=baum]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:disjunction", res.at("/query/operation").asText());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
- assertEquals("koral:token", res.at("/query/operands/0/operands/0/@type").asText());
- assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals("katze", res.at("/query/operands/0/operands/1/wrap/key").asText());
- assertEquals("eine", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals("baum", res.at("/query/operands/1/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:disjunction", res.at("/query/operation")
+ .asText());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:sequence", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("koral:token", res
+ .at("/query/operands/0/operands/0/@type").asText());
+ assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("katze", res.at("/query/operands/0/operands/1/wrap/key")
+ .asText());
+ assertEquals("eine", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("baum", res.at("/query/operands/1/operands/1/wrap/key")
+ .asText());
query = "[orth=der]([base=katze]|[orth=eine])[base=baum]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:disjunction", res.at("/query/operands/1/operation").asText());
- assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
- assertEquals("koral:token", res.at("/query/operands/2/@type").asText());
- assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("katze", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals("eine", res.at("/query/operands/1/operands/1/wrap/key").asText());
- assertEquals("baum", res.at("/query/operands/2/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:disjunction",
+ res.at("/query/operands/1/operation").asText());
+ assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:token", res.at("/query/operands/2/@type").asText());
+ assertEquals("der", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("katze", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("eine", res.at("/query/operands/1/operands/1/wrap/key")
+ .asText());
+ assertEquals("baum", res.at("/query/operands/2/wrap/key").asText());
query = "[orth=der][base=katze]|[orth=der][base=hund]|[orth=der][base=baum]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("der", res.at("/query/operands/2/operands/0/wrap/key").asText());
- assertEquals("baum", res.at("/query/operands/2/operands/1/wrap/key").asText());
+ assertEquals("der", res.at("/query/operands/2/operands/0/wrap/key")
+ .asText());
+ assertEquals("baum", res.at("/query/operands/2/operands/1/wrap/key")
+ .asText());
query = "[orth=der]([base=katze]|[base=hund]|[base=baum])";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:disjunction", res.at("/query/operands/1/operation").asText());
- assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
- assertEquals("koral:token", res.at("/query/operands/1/operands/0/@type").asText());
- assertEquals("koral:token", res.at("/query/operands/1/operands/1/@type").asText());
- assertEquals("koral:token", res.at("/query/operands/1/operands/2/@type").asText());
- assertEquals("katze", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals("hund", res.at("/query/operands/1/operands/1/wrap/key").asText());
- assertEquals("baum", res.at("/query/operands/1/operands/2/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:disjunction",
+ res.at("/query/operands/1/operation").asText());
+ assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:token", res
+ .at("/query/operands/1/operands/0/@type").asText());
+ assertEquals("koral:token", res
+ .at("/query/operands/1/operands/1/@type").asText());
+ assertEquals("koral:token", res
+ .at("/query/operands/1/operands/2/@type").asText());
+ assertEquals("katze", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("hund", res.at("/query/operands/1/operands/1/wrap/key")
+ .asText());
+ assertEquals("baum", res.at("/query/operands/1/operands/2/wrap/key")
+ .asText());
}
+
@Test
- public void testTokenSpanSequence() throws JsonProcessingException, IOException {
+ public void testTokenSpanSequence () throws JsonProcessingException,
+ IOException {
query = "[base=Mann]<vp>";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
- assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
- assertEquals("vp", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+ assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("koral:span", res.at("/query/operands/1/@type").asText());
+ assertEquals("vp", res.at("/query/operands/1/wrap/key").asText());
query = "<vp>[base=Mann]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
- assertEquals("vp", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
- assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("koral:span", res.at("/query/operands/0/@type").asText());
+ assertEquals("vp", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("koral:token", res.at("/query/operands/1/@type").asText());
+ assertEquals("Mann", res.at("/query/operands/1/wrap/key").asText());
query = "<vp>[base=Mann]<pp>";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:span", res.at("/query/operands/2/@type").asText());
- assertEquals("pp", res.at("/query/operands/2/wrap/key").asText());
+ assertEquals("koral:span", res.at("/query/operands/2/@type").asText());
+ assertEquals("pp", res.at("/query/operands/2/wrap/key").asText());
query = "<vp>[base=Mann]<pp><np>";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("pp", res.at("/query/operands/2/wrap/key").asText());
- assertEquals("np", res.at("/query/operands/3/wrap/key").asText());
+ assertEquals("pp", res.at("/query/operands/2/wrap/key").asText());
+ assertEquals("np", res.at("/query/operands/3/wrap/key").asText());
}
- @Test
- public void testClasses() throws JsonProcessingException, IOException {
+
+ @Test
+ public void testClasses () throws JsonProcessingException, IOException {
query = "{[base=Mann]}";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:class", res.at("/query/operation").asText());
- assertEquals(1, res.at("/query/classOut").asInt());
- assertEquals(true, res.at("/query/classIn").isMissingNode());
- assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:class", res.at("/query/operation").asText());
+ assertEquals(1, res.at("/query/classOut").asInt());
+ assertEquals(true, res.at("/query/classIn").isMissingNode());
+ assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
query = "{[base=Mann][orth=Frau]}";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:class", res.at("/query/operation").asText());
- assertEquals(1, res.at("/query/classOut").asInt());
- assertEquals(true, res.at("/query/classIn").isMissingNode());
- assertEquals("Mann", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals("Frau", res.at("/query/operands/0/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:class", res.at("/query/operation").asText());
+ assertEquals(1, res.at("/query/classOut").asInt());
+ assertEquals(true, res.at("/query/classIn").isMissingNode());
+ assertEquals("Mann", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("Frau", res.at("/query/operands/0/operands/1/wrap/key")
+ .asText());
query = "{[base=Mann]}{[orth=Frau]}";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operation").asText());
- assertEquals(1, res.at("/query/operands/0/classOut").asInt());
- assertEquals("operation:class", res.at("/query/operands/1/operation").asText());
- assertEquals(1, res.at("/query/operands/1/classOut").asInt());
- assertEquals(true, res.at("/query/classIn").isMissingNode());
- assertEquals("Mann", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals("Frau", res.at("/query/operands/1/operands/0/wrap/key").asText());
-
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("operation:class", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(1, res.at("/query/operands/0/classOut").asInt());
+ assertEquals("operation:class", res.at("/query/operands/1/operation")
+ .asText());
+ assertEquals(1, res.at("/query/operands/1/classOut").asInt());
+ assertEquals(true, res.at("/query/classIn").isMissingNode());
+ assertEquals("Mann", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("Frau", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+
query = "[p=NN]{[base=Mann][orth=Frau]}";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/1/operation").asText());
- assertEquals(1, res.at("/query/operands/1/classOut").asInt());
- assertEquals(true, res.at("/query/operands/1/classIn").isMissingNode());
- assertEquals("Mann", res.at("/query/operands/1/operands/0/operands/0/wrap/key").asText());
- assertEquals("Frau", res.at("/query/operands/1/operands/0/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("koral:group", res.at("/query/operands/1/@type").asText());
+ assertEquals("operation:class", res.at("/query/operands/1/operation")
+ .asText());
+ assertEquals(1, res.at("/query/operands/1/classOut").asInt());
+ assertEquals(true, res.at("/query/operands/1/classIn").isMissingNode());
+ assertEquals("Mann",
+ res.at("/query/operands/1/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("Frau",
+ res.at("/query/operands/1/operands/0/operands/1/wrap/key")
+ .asText());
query = "{[base=Mann][orth=Frau]}[p=NN]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operation").asText());
- assertEquals(1, res.at("/query/operands/0/classOut").asInt());
- assertEquals(true, res.at("/query/operands/0/classIn").isMissingNode());
- assertEquals("Mann", res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
- assertEquals("Frau", res.at("/query/operands/0/operands/0/operands/1/wrap/key").asText());
- assertEquals(1, res.at("/meta/highlight/0").asInt());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("koral:group", res.at("/query/operands/0/@type").asText());
+ assertEquals("operation:class", res.at("/query/operands/0/operation")
+ .asText());
+ assertEquals(1, res.at("/query/operands/0/classOut").asInt());
+ assertEquals(true, res.at("/query/operands/0/classIn").isMissingNode());
+ assertEquals("Mann",
+ res.at("/query/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("Frau",
+ res.at("/query/operands/0/operands/0/operands/1/wrap/key")
+ .asText());
+ assertEquals(1, res.at("/meta/highlight/0").asInt());
query = "{2:{1:[tt/p=ADJA]}[mate/p=NN]}";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:class", res.at("/query/operation").asText());
- assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
- assertEquals(2, res.at("/query/classOut").asInt());
- assertEquals(1, res.at("/query/operands/0/operands/0/classOut").asInt());
- assertEquals(2, res.at("/meta/highlight/0").asInt());
- assertEquals(1, res.at("/meta/highlight/1").asInt());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:class", res.at("/query/operation").asText());
+ assertEquals("operation:sequence", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals(2, res.at("/query/classOut").asInt());
+ assertEquals(1, res.at("/query/operands/0/operands/0/classOut").asInt());
+ assertEquals(2, res.at("/meta/highlight/0").asInt());
+ assertEquals(1, res.at("/meta/highlight/1").asInt());
}
+
@Test
- public void testFocusSplit() throws JsonProcessingException, IOException {
+ public void testFocusSplit () throws JsonProcessingException, IOException {
query = "focus([orth=Der]{[orth=Mann]})";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals(1, res.at("/query/classRef/0").asInt());
- assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
- assertEquals(1, res.at("/query/operands/0/operands/1/classOut").asInt());
- assertEquals("Mann", res.at("/query/operands/0/operands/1/operands/0/wrap/key").asText());
- assertEquals(1, res.at("/meta/highlight/0").asInt());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals(1, res.at("/query/classRef/0").asInt());
+ assertEquals("operation:sequence", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/1/operation").asText());
+ assertEquals(1, res.at("/query/operands/0/operands/1/classOut").asInt());
+ assertEquals("Mann",
+ res.at("/query/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals(1, res.at("/meta/highlight/0").asInt());
query = "focus([orth=Der]{[orth=Mann][orth=geht]})";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("operation:sequence", res.at("/query/operands/0/operands/1/operands/0/operation").asText());
- assertEquals("Mann", res.at("/query/operands/0/operands/1/operands/0/operands/0/wrap/key").asText());
- assertEquals("geht", res.at("/query/operands/0/operands/1/operands/0/operands/1/wrap/key").asText());
+ assertEquals("operation:sequence",
+ res.at("/query/operands/0/operands/1/operands/0/operation")
+ .asText());
+ assertEquals(
+ "Mann",
+ res.at("/query/operands/0/operands/1/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals(
+ "geht",
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/wrap/key")
+ .asText());
query = "focus(2:[orth=Der]{2:[orth=Mann][orth=geht]})";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(2, res.at("/query/classRef/0").asInt());
- assertEquals(2, res.at("/query/operands/0/operands/1/classOut").asInt());
- assertEquals(2, res.at("/meta/highlight/0").asInt());
+ assertEquals(2, res.at("/query/classRef/0").asInt());
+ assertEquals(2, res.at("/query/operands/0/operands/1/classOut").asInt());
+ assertEquals(2, res.at("/meta/highlight/0").asInt());
query = "focus(3:startswith(<s>,{3:<np>}))";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(3, res.at("/query/classRef/0").asInt());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operation").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
- assertEquals(3, res.at("/query/operands/0/operands/1/classOut").asInt());
- assertEquals("frames:startsWith", res.at("/query/operands/0/frames/0").asText());
- assertEquals(3, res.at("/meta/highlight/0").asInt());
+ assertEquals(3, res.at("/query/classRef/0").asInt());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals("operation:position", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/1/operation").asText());
+ assertEquals(3, res.at("/query/operands/0/operands/1/classOut").asInt());
+ assertEquals("frames:startsWith", res.at("/query/operands/0/frames/0")
+ .asText());
+ assertEquals(3, res.at("/meta/highlight/0").asInt());
query = "focus(1000:startswith(<s>,{1000:<np>}))";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(1000, res.at("/query/classRef/0").asInt());
- assertEquals(1000, res.at("/query/operands/0/operands/1/classOut").asInt());
- assertEquals(1000, res.at("/meta/highlight/0").asInt());
+ assertEquals(1000, res.at("/query/classRef/0").asInt());
+ assertEquals(1000, res.at("/query/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(1000, res.at("/meta/highlight/0").asInt());
query = "focus(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(3, res.at("/query/classRef/0").asInt());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals("operation:position", res.at("/query/operands/0/operation").asText());
- assertEquals("frames:startsWith", res.at("/query/operands/0/frames/0").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
- assertEquals(3, res.at("/query/operands/0/operands/1/classOut").asInt());
- assertEquals("operation:sequence", res.at("/query/operands/0/operands/1/operands/0/operation").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/1/operands/0/operands/1/operation").asText());
- assertEquals(1, res.at("/query/operands/0/operands/1/operands/0/operands/1/classOut").asInt());
- assertEquals("operation:sequence", res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operation").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operands/1/operation").asText());
- assertEquals(2, res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operands/1/classOut").asInt());
+ assertEquals(3, res.at("/query/classRef/0").asInt());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals("operation:position", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("frames:startsWith", res.at("/query/operands/0/frames/0")
+ .asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/1/operation").asText());
+ assertEquals(3, res.at("/query/operands/0/operands/1/classOut").asInt());
+ assertEquals("operation:sequence",
+ res.at("/query/operands/0/operands/1/operands/0/operation")
+ .asText());
+ assertEquals(
+ "operation:class",
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(
+ 1,
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/classOut")
+ .asInt());
+ assertEquals(
+ "operation:sequence",
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operation")
+ .asText());
+ assertEquals(
+ "operation:class",
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operands/1/operation")
+ .asText());
+ assertEquals(
+ 2,
+ res.at("/query/operands/0/operands/1/operands/0/operands/1/operands/0/operands/1/classOut")
+ .asInt());
query = "split(3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(3, res.at("/query/classRef/0").asInt());
- assertEquals(true, res.at("/query/classRef/1").isMissingNode());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:split", res.at("/query/operation").asText());
+ assertEquals(3, res.at("/query/classRef/0").asInt());
+ assertEquals(true, res.at("/query/classRef/1").isMissingNode());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:split", res.at("/query/operation").asText());
query = "split(2|3: startswith(<s>, {3:[base=der]{1:[mate/p=ADJA]{2:[tt/p=NN]}}}))";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(2, res.at("/query/classRef/0").asInt());
- assertEquals(3, res.at("/query/classRef/1").asInt());
- assertEquals("classRefOp:intersection", res.at("/query/classRefOp").asText());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:split", res.at("/query/operation").asText());
- assertEquals(3, res.at("/meta/highlight/0").asInt());
- assertEquals(1, res.at("/meta/highlight/1").asInt());
- assertEquals(2, res.at("/meta/highlight/2").asInt());
+ assertEquals(2, res.at("/query/classRef/0").asInt());
+ assertEquals(3, res.at("/query/classRef/1").asInt());
+ assertEquals("classRefOp:intersection", res.at("/query/classRefOp")
+ .asText());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:split", res.at("/query/operation").asText());
+ assertEquals(3, res.at("/meta/highlight/0").asInt());
+ assertEquals(1, res.at("/meta/highlight/1").asInt());
+ assertEquals(2, res.at("/meta/highlight/2").asInt());
query = "focus(1:{[base=der]}{1:[pos=ADJA]})";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(1, res.at("/query/classRef/0").asInt());
- assertEquals(1, res.at("/query/operands/0/operands/0/classOut").asInt());
- assertEquals(1, res.at("/query/operands/0/operands/1/classOut").asInt());
+ assertEquals(1, res.at("/query/classRef/0").asInt());
+ assertEquals(1, res.at("/query/operands/0/operands/0/classOut").asInt());
+ assertEquals(1, res.at("/query/operands/0/operands/1/classOut").asInt());
}
+
@Test
- public void testSubmatch() throws JsonProcessingException, IOException {
+ public void testSubmatch () throws JsonProcessingException, IOException {
query = "submatch(1:<s>)";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals(1, res.at("/query/spanRef/0").asInt());
- assertEquals(true, res.at("/query/spanRef/1").isMissingNode());
- assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals(1, res.at("/query/spanRef/0").asInt());
+ assertEquals(true, res.at("/query/spanRef/1").isMissingNode());
+ assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
query = "submatch(1,4:<s>)";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals(1, res.at("/query/spanRef/0").asInt());
- assertEquals(4, res.at("/query/spanRef/1").asInt());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals(1, res.at("/query/spanRef/0").asInt());
+ assertEquals(4, res.at("/query/spanRef/1").asInt());
query = "submatch(1,4:contains(<s>,[base=Haus]))";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:reference", res.at("/query/@type").asText());
- assertEquals("operation:focus", res.at("/query/operation").asText());
- assertEquals(1, res.at("/query/spanRef/0").asInt());
- assertEquals(4, res.at("/query/spanRef/1").asInt());
- assertEquals("frames:isAround", res.at("/query/operands/0/frames/0").asText());
- assertEquals("s", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals("Haus", res.at("/query/operands/0/operands/1/wrap/key").asText());
+ assertEquals("koral:reference", res.at("/query/@type").asText());
+ assertEquals("operation:focus", res.at("/query/operation").asText());
+ assertEquals(1, res.at("/query/spanRef/0").asInt());
+ assertEquals(4, res.at("/query/spanRef/1").asInt());
+ assertEquals("frames:isAround", res.at("/query/operands/0/frames/0")
+ .asText());
+ assertEquals("s", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("Haus", res.at("/query/operands/0/operands/1/wrap/key")
+ .asText());
}
+
+
@Test
- public void testRelations() throws JsonProcessingException, IOException {
+ public void testRelations () throws JsonProcessingException, IOException {
query = "dominates(<s>,<np>)";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:relation", res.at("/query/operation").asText());
- assertEquals("koral:relation", res.at("/query/relation/@type").asText());
- assertEquals("c", res.at("/query/relation/wrap/layer").asText());
- assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("np", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+ assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+ assertEquals("s", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("np", res.at("/query/operands/1/wrap/key").asText());
query = "relatesTo([base=Baum],<np>)";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:relation", res.at("/query/operation").asText());
- assertEquals("koral:relation", res.at("/query/relation/@type").asText());
- assertEquals("Baum", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("np", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:relation", res.at("/query/operation").asText());
+ assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+ assertEquals("Baum", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("np", res.at("/query/operands/1/wrap/key").asText());
query = "relatesTo(Baum,<np>)";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("orth", res.at("/query/operands/0/wrap/layer").asText());
- assertEquals("Baum", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("orth", res.at("/query/operands/0/wrap/layer").asText());
+ assertEquals("Baum", res.at("/query/operands/0/wrap/key").asText());
query = "relatesTo(mate/d=HEAD:<np>,[base=Baum])";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("lemma", res.at("/query/operands/1/wrap/layer").asText());
- assertEquals("Baum", res.at("/query/operands/1/wrap/key").asText());
- assertEquals("koral:relation", res.at("/query/relation/@type").asText());
- assertEquals("mate", res.at("/query/relation/wrap/foundry").asText());
- assertEquals("d", res.at("/query/relation/wrap/layer").asText());
- assertEquals("HEAD", res.at("/query/relation/wrap/key").asText());
+ assertEquals("lemma", res.at("/query/operands/1/wrap/layer").asText());
+ assertEquals("Baum", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+ assertEquals("mate", res.at("/query/relation/wrap/foundry").asText());
+ assertEquals("d", res.at("/query/relation/wrap/layer").asText());
+ assertEquals("HEAD", res.at("/query/relation/wrap/key").asText());
query = "dependency([base=fällen],[base=Baum])";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("lemma", res.at("/query/operands/0/wrap/layer").asText());
- assertEquals("fällen", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("lemma", res.at("/query/operands/1/wrap/layer").asText());
- assertEquals("Baum", res.at("/query/operands/1/wrap/key").asText());
- assertEquals("koral:relation", res.at("/query/relation/@type").asText());
- assertEquals("d", res.at("/query/relation/wrap/layer").asText());
+ assertEquals("lemma", res.at("/query/operands/0/wrap/layer").asText());
+ assertEquals("fällen", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("lemma", res.at("/query/operands/1/wrap/layer").asText());
+ assertEquals("Baum", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+ assertEquals("d", res.at("/query/relation/wrap/layer").asText());
query = "dominates(Baum,<np>)";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("orth", res.at("/query/operands/0/wrap/layer").asText());
- assertEquals("Baum", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("koral:relation", res.at("/query/relation/@type").asText());
- assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+ assertEquals("orth", res.at("/query/operands/0/wrap/layer").asText());
+ assertEquals("Baum", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("koral:relation", res.at("/query/relation/@type").asText());
+ assertEquals("c", res.at("/query/relation/wrap/layer").asText());
query = "dominates(cnx/c:<vp>,<np>)";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("cnx", res.at("/query/relation/wrap/foundry").asText());
- assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+ assertEquals("cnx", res.at("/query/relation/wrap/foundry").asText());
+ assertEquals("c", res.at("/query/relation/wrap/layer").asText());
query = "dominates(cnx/c*:<vp>,<np>)";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("cnx", res.at("/query/relation/wrap/foundry").asText());
- assertEquals("c", res.at("/query/relation/wrap/layer").asText());
- assertEquals(0, res.at("/query/relation/boundary/min").asInt());
- assertEquals(true, res.at("/query/relation/boundary/max").isMissingNode());
+ assertEquals("cnx", res.at("/query/relation/wrap/foundry").asText());
+ assertEquals("c", res.at("/query/relation/wrap/layer").asText());
+ assertEquals(0, res.at("/query/relation/boundary/min").asInt());
+ assertEquals(true, res.at("/query/relation/boundary/max")
+ .isMissingNode());
query = "dominates(cnx/c{1,5}:<vp>,<np>)";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(1, res.at("/query/relation/boundary/min").asInt());
- assertEquals(5, res.at("/query/relation/boundary/max").asInt());
+ assertEquals(1, res.at("/query/relation/boundary/min").asInt());
+ assertEquals(5, res.at("/query/relation/boundary/max").asInt());
query = "dominates(cnx/c{,5}:<vp>,<np>)";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(0, res.at("/query/relation/boundary/min").asInt());
- assertEquals(5, res.at("/query/relation/boundary/max").asInt());
+ assertEquals(0, res.at("/query/relation/boundary/min").asInt());
+ assertEquals(5, res.at("/query/relation/boundary/max").asInt());
query = "dominates(cnx/c{5}:<vp>,<np>)";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals(5, res.at("/query/relation/boundary/min").asInt());
- assertEquals(5, res.at("/query/relation/boundary/max").asInt());
+ assertEquals(5, res.at("/query/relation/boundary/min").asInt());
+ assertEquals(5, res.at("/query/relation/boundary/max").asInt());
}
+
@Test
- public void testAlign() throws JsonProcessingException, IOException {
+ public void testAlign () throws JsonProcessingException, IOException {
query = "[orth=der]^[orth=Mann]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals(1, res.at("/query/operands/0/classOut").asInt());
- assertEquals("Mann", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals("operation:class", res.at("/query/operands/1/operation").asText());
- assertEquals(2, res.at("/query/operands/1/classOut").asInt());
- assertEquals(1, res.at("/meta/alignment/0/0").asInt());
- assertEquals(2, res.at("/meta/alignment/0/1").asInt());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals(1, res.at("/query/operands/0/classOut").asInt());
+ assertEquals("Mann", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("operation:class", res.at("/query/operands/1/operation")
+ .asText());
+ assertEquals(2, res.at("/query/operands/1/classOut").asInt());
+ assertEquals(1, res.at("/meta/alignment/0/0").asInt());
+ assertEquals(2, res.at("/meta/alignment/0/1").asInt());
query = "[orth=der]^[orth=große][orth=Mann]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals(1, res.at("/query/operands/0/classOut").asInt());
- assertEquals("große", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals("operation:class", res.at("/query/operands/1/operation").asText());
- assertEquals(2, res.at("/query/operands/1/classOut").asInt());
- assertEquals("Mann", res.at("/query/operands/2/wrap/key").asText());
- assertEquals(1, res.at("/meta/alignment/0/0").asInt());
- assertEquals(2, res.at("/meta/alignment/0/1").asInt());
-
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals(1, res.at("/query/operands/0/classOut").asInt());
+ assertEquals("große", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("operation:class", res.at("/query/operands/1/operation")
+ .asText());
+ assertEquals(2, res.at("/query/operands/1/classOut").asInt());
+ assertEquals("Mann", res.at("/query/operands/2/wrap/key").asText());
+ assertEquals(1, res.at("/meta/alignment/0/0").asInt());
+ assertEquals(2, res.at("/meta/alignment/0/1").asInt());
+
query = "([base=a]^[base=b])|[base=c]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("operation:disjunction", res.at("/query/operation").asText());
- assertEquals("operation:sequence", res.at("/query/operands/0/operation").asText());
- assertEquals("operation:class", res.at("/query/operands/0/operands/1/operation").asText());
- assertEquals("a", res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
- assertEquals("b", res.at("/query/operands/0/operands/1/operands/0/wrap/key").asText());
- assertEquals("c", res.at("/query/operands/1/wrap/key").asText());
- assertEquals(1, res.at("/query/operands/0/operands/0/classOut").asInt());
- assertEquals(2, res.at("/query/operands/0/operands/1/classOut").asInt());
- assertEquals(1, res.at("/meta/alignment/0/0").asInt());
- assertEquals(2, res.at("/meta/alignment/0/1").asInt());
+ assertEquals("operation:disjunction", res.at("/query/operation")
+ .asText());
+ assertEquals("operation:sequence", res
+ .at("/query/operands/0/operation").asText());
+ assertEquals("operation:class",
+ res.at("/query/operands/0/operands/1/operation").asText());
+ assertEquals("a",
+ res.at("/query/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("b",
+ res.at("/query/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("c", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals(1, res.at("/query/operands/0/operands/0/classOut").asInt());
+ assertEquals(2, res.at("/query/operands/0/operands/1/classOut").asInt());
+ assertEquals(1, res.at("/meta/alignment/0/0").asInt());
+ assertEquals(2, res.at("/meta/alignment/0/1").asInt());
query = "([base=a]^[base=b][base=c])|[base=d]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("a", res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
- assertEquals("b", res.at("/query/operands/0/operands/1/operands/0/wrap/key").asText());
- assertEquals("c", res.at("/query/operands/0/operands/2/wrap/key").asText());
- assertEquals("d", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("a",
+ res.at("/query/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("b",
+ res.at("/query/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("c", res.at("/query/operands/0/operands/2/wrap/key")
+ .asText());
+ assertEquals("d", res.at("/query/operands/1/wrap/key").asText());
query = "([base=a]^[base=b]^[base=c])|[base=d]";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("a", res.at("/query/operands/0/operands/0/operands/0/wrap/key").asText());
- assertEquals(1, res.at("/query/operands/0/operands/0/classOut").asInt());
- assertEquals("b", res.at("/query/operands/0/operands/1/operands/0/wrap/key").asText());
- assertEquals(2, res.at("/query/operands/0/operands/1/classOut").asInt());
- assertEquals("c", res.at("/query/operands/0/operands/2/operands/0/wrap/key").asText());
- assertEquals(3, res.at("/query/operands/0/operands/2/classOut").asInt());
- assertEquals("d", res.at("/query/operands/1/wrap/key").asText());
- assertEquals(1, res.at("/meta/alignment/0/0").asInt());
- assertEquals(2, res.at("/meta/alignment/0/1").asInt());
- assertEquals(2, res.at("/meta/alignment/1/0").asInt());
- assertEquals(3, res.at("/meta/alignment/1/1").asInt());
-
+ assertEquals("a",
+ res.at("/query/operands/0/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals(1, res.at("/query/operands/0/operands/0/classOut").asInt());
+ assertEquals("b",
+ res.at("/query/operands/0/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals(2, res.at("/query/operands/0/operands/1/classOut").asInt());
+ assertEquals("c",
+ res.at("/query/operands/0/operands/2/operands/0/wrap/key")
+ .asText());
+ assertEquals(3, res.at("/query/operands/0/operands/2/classOut").asInt());
+ assertEquals("d", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals(1, res.at("/meta/alignment/0/0").asInt());
+ assertEquals(2, res.at("/meta/alignment/0/1").asInt());
+ assertEquals(2, res.at("/meta/alignment/1/0").asInt());
+ assertEquals(3, res.at("/meta/alignment/1/1").asInt());
+
query = "^ Mann";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("operation:class", res.at("/query/operation").asText());
- assertEquals(1, res.at("/query/classOut").asInt());
- assertEquals(-1, res.at("/meta/alignment/0/0").asInt());
- assertEquals(1, res.at("/meta/alignment/0/1").asInt());
-
+ assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("operation:class", res.at("/query/operation").asText());
+ assertEquals(1, res.at("/query/classOut").asInt());
+ assertEquals(-1, res.at("/meta/alignment/0/0").asInt());
+ assertEquals(1, res.at("/meta/alignment/0/1").asInt());
+
query = "Mann ^";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("operation:class", res.at("/query/operation").asText());
- assertEquals(1, res.at("/query/classOut").asInt());
- assertEquals(1, res.at("/meta/alignment/0/0").asInt());
- assertEquals(-1, res.at("/meta/alignment/0/1").asInt());
+ assertEquals("Mann", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("operation:class", res.at("/query/operation").asText());
+ assertEquals(1, res.at("/query/classOut").asInt());
+ assertEquals(1, res.at("/meta/alignment/0/0").asInt());
+ assertEquals(-1, res.at("/meta/alignment/0/1").asInt());
}
+
@Test
- public void testSimpleQueries() throws JsonProcessingException, IOException {
+ public void testSimpleQueries () throws JsonProcessingException,
+ IOException {
query = "Baum";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:token", res.at("/query/@type").asText());
- assertEquals("koral:term", res.at("/query/wrap/@type").asText());
- assertEquals("Baum", res.at("/query/wrap/key").asText());
- assertEquals("orth", res.at("/query/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/wrap/match").asText());
+ assertEquals("koral:token", res.at("/query/@type").asText());
+ assertEquals("koral:term", res.at("/query/wrap/@type").asText());
+ assertEquals("Baum", res.at("/query/wrap/key").asText());
+ assertEquals("orth", res.at("/query/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/wrap/match").asText());
query = "Der Baum";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("koral:group", res.at("/query/@type").asText());
- assertEquals("operation:sequence", res.at("/query/operation").asText());
- assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
- assertEquals("koral:term", res.at("/query/operands/0/wrap/@type").asText());
- assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("Baum", res.at("/query/operands/1/wrap/key").asText());
- assertEquals("orth", res.at("/query/operands/0/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/operands/0/wrap/match").asText());
- assertEquals("orth", res.at("/query/operands/1/wrap/layer").asText());
- assertEquals("match:eq", res.at("/query/operands/1/wrap/match").asText());
+ assertEquals("koral:group", res.at("/query/@type").asText());
+ assertEquals("operation:sequence", res.at("/query/operation").asText());
+ assertEquals("koral:token", res.at("/query/operands/0/@type").asText());
+ assertEquals("koral:term", res.at("/query/operands/0/wrap/@type")
+ .asText());
+ assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("Baum", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("orth", res.at("/query/operands/0/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/operands/0/wrap/match")
+ .asText());
+ assertEquals("orth", res.at("/query/operands/1/wrap/layer").asText());
+ assertEquals("match:eq", res.at("/query/operands/1/wrap/match")
+ .asText());
query = "Der große Baum";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("große", res.at("/query/operands/1/wrap/key").asText());
- assertEquals("Baum", res.at("/query/operands/2/wrap/key").asText());
+ assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("große", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("Baum", res.at("/query/operands/2/wrap/key").asText());
query = "Der (große|kleine) Baum";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("operation:disjunction", res.at("/query/operands/1/operation").asText());
- assertEquals("große", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals("kleine", res.at("/query/operands/1/operands/1/wrap/key").asText());
- assertEquals("Baum", res.at("/query/operands/2/wrap/key").asText());
+ assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("operation:disjunction",
+ res.at("/query/operands/1/operation").asText());
+ assertEquals("große", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("kleine", res.at("/query/operands/1/operands/1/wrap/key")
+ .asText());
+ assertEquals("Baum", res.at("/query/operands/2/wrap/key").asText());
query = "der große Baum | der kleine Baum";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("operation:disjunction", res.at("/query/operation").asText());
- assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key").asText());
- assertEquals("große", res.at("/query/operands/0/operands/1/wrap/key").asText());
- assertEquals("Baum", res.at("/query/operands/0/operands/2/wrap/key").asText());
- assertEquals("der", res.at("/query/operands/1/operands/0/wrap/key").asText());
- assertEquals("kleine", res.at("/query/operands/1/operands/1/wrap/key").asText());
- assertEquals("Baum", res.at("/query/operands/1/operands/2/wrap/key").asText());
+ assertEquals("operation:disjunction", res.at("/query/operation")
+ .asText());
+ assertEquals("der", res.at("/query/operands/0/operands/0/wrap/key")
+ .asText());
+ assertEquals("große", res.at("/query/operands/0/operands/1/wrap/key")
+ .asText());
+ assertEquals("Baum", res.at("/query/operands/0/operands/2/wrap/key")
+ .asText());
+ assertEquals("der", res.at("/query/operands/1/operands/0/wrap/key")
+ .asText());
+ assertEquals("kleine", res.at("/query/operands/1/operands/1/wrap/key")
+ .asText());
+ assertEquals("Baum", res.at("/query/operands/1/operands/2/wrap/key")
+ .asText());
query = "Der [p=ADJA] Baum";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
- assertEquals("ADJA", res.at("/query/operands/1/wrap/key").asText());
- assertEquals("p", res.at("/query/operands/1/wrap/layer").asText());
- assertEquals("Baum", res.at("/query/operands/2/wrap/key").asText());
+ assertEquals("Der", res.at("/query/operands/0/wrap/key").asText());
+ assertEquals("ADJA", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("p", res.at("/query/operands/1/wrap/layer").asText());
+ assertEquals("Baum", res.at("/query/operands/2/wrap/key").asText());
}
+
@Test
- public void testWithin() throws JsonProcessingException, IOException {
+ public void testWithin () throws JsonProcessingException, IOException {
query = "[p=VVFIN] within s";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("operation:position", res.at("/query/operation").asText());
- assertEquals("frames:isAround", res.at("/query/frames/0").asText());
- assertEquals("s", res.at("/query/operands/0/key").asText());
- assertEquals("VVFIN", res.at("/query/operands/1/wrap/key").asText());
+ assertEquals("operation:position", res.at("/query/operation").asText());
+ assertEquals("frames:isAround", res.at("/query/frames/0").asText());
+ assertEquals("s", res.at("/query/operands/0/key").asText());
+ assertEquals("VVFIN", res.at("/query/operands/1/wrap/key").asText());
}
+
@Test
- public void testMeta() throws JsonProcessingException, IOException {
+ public void testMeta () throws JsonProcessingException, IOException {
query = "x meta textClass=Sport";
qs.setQuery(query, "poliqarpplus");
res = mapper.readTree(qs.toJSON());
- assertEquals("x", res.at("/query/wrap/key").asText());
- assertEquals("koral:doc", res.at("/collection/@type").asText());
- assertEquals("textClass", res.at("/collection/key").asText());
- assertEquals("Sport", res.at("/collection/value").asText());
+ assertEquals("x", res.at("/query/wrap/key").asText());
+ assertEquals("koral:doc", res.at("/collection/@type").asText());
+ assertEquals("textClass", res.at("/collection/key").asText());
+ assertEquals("Sport", res.at("/collection/value").asText());
query = "x meta textClass=Sport";
qs.setQuery(query, "poliqarpplus");
qs.setCollection("author=Smith");
res = mapper.readTree(qs.toJSON());
- assertEquals("x", res.at("/query/wrap/key").asText());
- assertEquals("koral:docGroup", res.at("/collection/@type").asText());
- assertEquals("operation:and", res.at("/collection/operation").asText());
- assertEquals("textClass", res.at("/collection/operands/0/key").asText());
- assertEquals("Sport", res.at("/collection/operands/0/value").asText());
- assertEquals("author", res.at("/collection/operands/1/key").asText());
- assertEquals("Smith", res.at("/collection/operands/1/value").asText());
+ assertEquals("x", res.at("/query/wrap/key").asText());
+ assertEquals("koral:docGroup", res.at("/collection/@type").asText());
+ assertEquals("operation:and", res.at("/collection/operation").asText());
+ assertEquals("textClass", res.at("/collection/operands/0/key").asText());
+ assertEquals("Sport", res.at("/collection/operands/0/value").asText());
+ assertEquals("author", res.at("/collection/operands/1/key").asText());
+ assertEquals("Smith", res.at("/collection/operands/1/value").asText());
// TODO more tests
}