Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ental into jetta
  • Loading branch information
Necr0x0Der committed Jul 1, 2024
2 parents 4990159 + 472ced4 commit 4df4a2f
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 38 deletions.
3 changes: 2 additions & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ FROM ubuntu:22.04
RUN apt-get update && \
DEBIAN_FRONTEND=noninteractive \
TZ=UTC \
apt-get install -y sudo git python3 python3-pip curl gcc cmake && \
apt-get install -y sudo git python3 python3-pip curl gcc cmake \
pkg-config libssl-dev zlib1g-dev && \
rm -rf /var/lib/apt/lists/*

RUN echo '%sudo ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ Rust (see the Notes at the installation page).
* GCC (7.5 or later)
* CMake (3.19 or later)

To support Git based modules (enabled by default):
* OpenSSL library
* Zlib library

* Install cbindgen:
```
cargo install --force cbindgen
Expand Down
18 changes: 9 additions & 9 deletions lib/src/atom/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,10 @@ fn match_atoms_recursively(left: &Atom, right: &Atom) -> BindingsSet {
let res = match (left, right) {
(Atom::Symbol(a), Atom::Symbol(b)) if a == b => BindingsSet::single(),
(Atom::Variable(dv), Atom::Variable(pv)) => BindingsSet::single().add_var_equality(dv, pv),
// TODO: If GroundedAtom is matched with VariableAtom there are
// two way to calculate match: (1) pass variable to the
// GroundedAtom::match(); (2) assign GroundedAtom to the Variable.
// Returning both results breaks tests right now.
(Atom::Variable(v), b) => BindingsSet::single().add_var_binding(v, b),
(a, Atom::Variable(v)) => BindingsSet::single().add_var_binding(v, a),
(Atom::Expression(ExpressionAtom{ children: a }), Atom::Expression(ExpressionAtom{ children: b }))
Expand All @@ -1141,17 +1145,13 @@ fn match_atoms_recursively(left: &Atom, right: &Atom) -> BindingsSet {
acc.merge(&match_atoms_recursively(a, b))
})
},
// TODO: one more case for the special flag to see if GroundedAtom is
// matchable. If GroundedAtom is matched with VariableAtom there are
// two way to calculate match: (1) pass variable to the
// GroundedAtom::match(); (2) assign GroundedAtom to the Variable.
// Returning both results breaks tests right now.
(Atom::Grounded(a), _) => {
a.match_(right).collect()
(Atom::Grounded(a), _) if a.as_grounded().as_match().is_some() => {
a.as_grounded().as_match().unwrap().match_(right).collect()
},
(_, Atom::Grounded(b)) => {
b.match_(left).collect()
(_, Atom::Grounded(b)) if b.as_grounded().as_match().is_some() => {
b.as_grounded().as_match().unwrap().match_(left).collect()
},
(Atom::Grounded(a), Atom::Grounded(b)) if a.eq_gnd(AsRef::as_ref(b)) => BindingsSet::single(),
_ => BindingsSet::empty(),
};
log::trace!("match_atoms_recursively: {} ~ {} => {}", left, right, res);
Expand Down
25 changes: 7 additions & 18 deletions lib/src/atom/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,23 +346,6 @@ pub trait GroundedAtom : Any + Debug + Display {
fn type_(&self) -> Atom {
self.as_grounded().type_()
}
fn match_(&self, other: &Atom) -> matcher::MatchResultIter {
match self.as_grounded().as_match() {
Some(match_) => match_.match_(other),
None => {
let equal = match other {
Atom::Grounded(other) => self.eq_gnd(other.as_ref()),
_ => false,
};
let result = if equal {
matcher::BindingsSet::single()
} else {
matcher::BindingsSet::empty()
};
Box::new(result.into_iter())
},
}
}
// A mutable reference is used here instead of a type parameter because
// the type parameter makes impossible using GroundedAtom reference in the
// Atom::Grounded. On the other hand the only advantage of using the type
Expand Down Expand Up @@ -594,7 +577,13 @@ pub fn match_by_bidirectional_equality<T>(this: &T, other: &Atom) -> matcher::Ma
} else {
let temp_atom = Atom::gnd(this.clone());
match other {
Atom::Grounded(gnd) => gnd.match_(&temp_atom),
Atom::Grounded(gnd) => {
if let Some(matchable) = gnd.as_grounded().as_match() {
matchable.match_(&temp_atom)
} else {
Box::new(std::iter::empty())
}
},
_ => Box::new(std::iter::empty()),
}
}
Expand Down
25 changes: 19 additions & 6 deletions python/hyperon/exts/das_gate/dasgate.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class DASpace(AbstractSpace):
def __init__(self, remote=False, host='localhost', port='22', unwrap=True):
super().__init__()
# self.das = DistributedAtomSpace('ram_only')
self.fetch_flag = False
if remote:
self.das = DistributedAtomSpace(query_engine='remote', host=host, port=port)
self.remote = True
Expand Down Expand Up @@ -163,6 +164,14 @@ def _query_actual_helper_no_iter(self, answer, new_bindings_set):
new_bindings_set.push(bindings)
return new_bindings_set

def _query_fetch_helper(self, answer, new_bindings_set):
for mapping, subgraph in answer:
bindings = Bindings()
for var, val in mapping.mapping.items():
# remove '$', because it is automatically added
bindings.add_var_binding(V(var[1:]), self._handle2atom(val))
new_bindings_set.push(bindings)
return new_bindings_set

def query(self, query_atom):
query = self._atom2dict_new(query_atom)
Expand All @@ -179,13 +188,17 @@ def query(self, query_atom):
if not answer:
return new_bindings_set

if self.remote:
return self._query_actual_helper(answer, new_bindings_set)
# return self._query_actual_helper_no_iter(answer, new_bindings_set)
# return self._query_temp_helper(answer, new_bindings_set)
if self.fetch_flag:
self.das.fetch()
return self._query_fetch_helper(answer, new_bindings_set)
else:
#return self._query_actual_helper_no_iter(answer, new_bindings_set)
return self._query_actual_helper(answer, new_bindings_set)
if self.remote:
return self._query_actual_helper(answer, new_bindings_set)
# return self._query_actual_helper_no_iter(answer, new_bindings_set)
# return self._query_temp_helper(answer, new_bindings_set)
else:
#return self._query_actual_helper_no_iter(answer, new_bindings_set)
return self._query_actual_helper(answer, new_bindings_set)

# return new_bindings_set

Expand Down
5 changes: 1 addition & 4 deletions python/integration/test_bio_das.metta
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@

;!(match &das ($t MYBPP) ($t MYBPP))
!(match &das ($t MYBPP) ($t MYBPP))
!(match &das (translation_of (protein "O43264") (transcript "ENST00000200135")) OK)
;!(match &das (translation_of (protein "O43264") (transcript "ENST00000200135")) OK)

!(assertEqualToResult
(match &das (translation_of (protein "O43264") (transcript "ENST00000200135")) OK)
())

!(match &das (translation_of (protein O43264) (transcript ENST00000200135)) OK)

Expand Down

0 comments on commit 4df4a2f

Please sign in to comment.