Skip to content

Commit

Permalink
Merge #200
Browse files Browse the repository at this point in the history
200: Implement negation for non-existing nodes r=thomaskrause a=thomaskrause

This implements #187 but does not implement the more complex structures (as described in #199) yet. Also note that we changed form a prefix ? to a suffix, to make it easier to implement optional parts of the query term in the AQL parser later on when needed.

We implement these negated operators with non-existent operands as unary operators (with the existing node as the one that is filtered using the non-existent expression). There is also some refactoring and renaming to make it easier to use the value filter functions outside the conjunction code (in our operator) to avoid duplicated implementation of the node search logic.

Co-authored-by: Thomas Krause <[email protected]>
Co-authored-by: Thomas Krause <[email protected]>
  • Loading branch information
3 people authored Sep 16, 2021
2 parents efcd074 + 3defb77 commit bab4cc3
Show file tree
Hide file tree
Showing 35 changed files with 1,009 additions and 531 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added

- Added generic operator negation without existence assumption,
if only one side of the negated operator is optional (#187).

## [1.1.0] - 2021-09-09

### Added

- Added generic operator negation with existance assumption by adding `!` before the binary operator (#186)
- Added generic operator negation with existence assumption by adding `!` before the binary operator (#186)

### Changed

Expand Down
11 changes: 6 additions & 5 deletions core/src/annostorage/inmemory.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{AnnotationStorage, Match, MatchGroup};
use super::{AnnotationStorage, Match};
use crate::annostorage::ValueSearch;
use crate::errors::Result;
use crate::malloc_size_of::MallocSizeOf;
Expand All @@ -8,6 +8,7 @@ use crate::{annostorage::symboltable::SymbolTable, errors::GraphAnnisCoreError};
use core::ops::Bound::*;
use itertools::Itertools;
use rustc_hash::{FxHashMap, FxHashSet};
use smallvec::SmallVec;
use smartstring::alias::String;
use std::borrow::Cow;
use std::collections::{BTreeMap, HashMap};
Expand Down Expand Up @@ -407,11 +408,11 @@ where
ns: Option<&str>,
name: Option<&str>,
it: Box<dyn Iterator<Item = T>>,
) -> MatchGroup {
) -> SmallVec<[Match; 8]> {
if let Some(name) = name {
if let Some(ns) = ns {
// return the only possible annotation for each node
let mut matches = MatchGroup::new();
let mut matches = SmallVec::<[Match; 8]>::new();
let key = Arc::from(AnnoKey {
ns: ns.into(),
name: name.into(),
Expand Down Expand Up @@ -441,7 +442,7 @@ where
})
.collect();
// return all annotations with the correct name for each node
let mut matches = MatchGroup::new();
let mut matches = SmallVec::<[Match; 8]>::new();
for item in it {
for (key_symbol, key) in matching_key_symbols.iter() {
if let Some(all_annos) = self.by_container.get(&item) {
Expand All @@ -458,7 +459,7 @@ where
}
} else {
// return all annotations for each node
let mut matches = MatchGroup::new();
let mut matches = SmallVec::<[Match; 8]>::new();
for item in it {
let all_keys = self.get_all_keys_for_item(&item, None, None);
for anno_key in all_keys {
Expand Down
4 changes: 2 additions & 2 deletions core/src/annostorage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,13 +155,13 @@ where

/// Get the matching annotation keys for each item in the iterator.
///
/// This function allows to filter the received annotation keys by the specifying the namespace and name.
/// This function allows to filter the received annotation keys by specifying the namespace and name.
fn get_keys_for_iterator(
&self,
ns: Option<&str>,
name: Option<&str>,
it: Box<dyn Iterator<Item = T>>,
) -> MatchGroup;
) -> SmallVec<[Match; 8]>;

/// Return the total number of annotations contained in this `AnnotationStorage`.
fn number_of_annotations(&self) -> usize;
Expand Down
9 changes: 4 additions & 5 deletions core/src/annostorage/ondisk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ use crate::util::disk_collections::{DiskMap, EvictionStrategy};
use crate::util::{self, memory_estimation};
use core::ops::Bound::*;
use rand::seq::IteratorRandom;
use smallvec::SmallVec;
use std::borrow::Cow;
use std::collections::{BTreeMap, HashMap, HashSet};
use std::path::{Path, PathBuf};
use std::sync::Arc;

use smartstring::alias::String as SmartString;

use super::MatchGroup;

pub const SUBFOLDER_NAME: &str = "nodes_diskmap_v1";

const UTF_8_MSG: &str = "String must be valid UTF-8 but was corrupted";
Expand Down Expand Up @@ -464,15 +463,15 @@ where
ns: Option<&str>,
name: Option<&str>,
it: Box<dyn Iterator<Item = T>>,
) -> MatchGroup {
) -> SmallVec<[Match; 8]> {
if let Some(name) = name {
if let Some(ns) = ns {
// return the only possible annotation for each node
let key = Arc::from(AnnoKey {
ns: ns.into(),
name: name.into(),
});
let mut matches = MatchGroup::new();
let mut matches = SmallVec::<[Match; 8]>::new();
if let Some(symbol_id) = self.anno_key_symbols.get_symbol(&key) {
// create a template key
let mut container_key = create_by_container_key(T::default(), symbol_id);
Expand Down Expand Up @@ -500,7 +499,7 @@ where
})
.collect();
// return all annotations with the correct name for each node
let mut matches = MatchGroup::new();
let mut matches = SmallVec::<[Match; 8]>::new();
for item in it {
for (container_key, anno_key) in matching_qnames.iter_mut() {
// Set the first bytes to the ID of the item.
Expand Down
2 changes: 2 additions & 0 deletions graphannis/src/annis/db/aql/ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ pub enum Literal {
spec: NodeSearchSpec,
pos: Option<Pos>,
variable: Option<String>,
optional: bool,
},
BinaryOp {
lhs: Operand,
Expand All @@ -63,6 +64,7 @@ pub enum Operand {
spec: Rc<NodeSearchSpec>,
pos: Pos,
variable: Option<String>,
optional: bool,
},
}

Expand Down
Loading

0 comments on commit bab4cc3

Please sign in to comment.