Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Wrap types from rio to have views and normal owning types #23

Merged
merged 12 commits into from
Jul 10, 2024

Conversation

supermaxiste
Copy link
Member

Proposed Changes

Draft: adding new types from rio using String instead of &str

Types of Changes

What types of changes does your code introduce? Put an x in the boxes that
apply

  • A bug fix (non-breaking change which fixes an issue).
  • A new feature (non-breaking change which adds functionality).
  • A breaking change (fix or feature that would cause existing
    functionality to not work as expected).
  • A non-productive update (documentation, tooling, etc. if none of the
    other choices apply).

Checklist

  • I have read the
    CONTRIBUTING
    guidelines.
  • I have added tests that prove my fix is effective or that my feature
    works.
  • I have added the necessary documentation (if appropriate).

Further Comments

If you could check both rdf_types.rsand model.rs that would be great. Before moving forward I need to see if you're fine with this solution. Important notes:

  • The Copy trait doesn't work anymore, I think because we're not dealing with&str anymore?
  • We cannot include RDF-Star in our types because it causes a loop in our definition that Rust doesn't like. For example Triple including Subject and Subject including Triple. This cycle breaks the query system: https://rustc-dev-guide.rust-lang.org/query.html. The only way to avoid it is to use &str
  • I had to bring over the Display functions too, otherwise the rest doesn't work

src/model.rs Outdated Show resolved Hide resolved
src/rdf_types.rs Outdated Show resolved Hide resolved
src/rdf_types.rs Show resolved Hide resolved
src/rdf_types.rs Show resolved Hide resolved
src/rdf_types.rs Show resolved Hide resolved
src/rdf_types.rs Show resolved Hide resolved
src/model.rs Outdated Show resolved Hide resolved
src/model.rs Outdated Show resolved Hide resolved
src/model.rs Outdated Show resolved Hide resolved
src/model.rs Outdated Show resolved Hide resolved
src/model.rs Outdated Show resolved Hide resolved
@gabyx gabyx changed the title Feat/hash feat: Wrap types from rio to have views and normal owning types Jul 6, 2024
@supermaxiste
Copy link
Member Author

Update

  • Added rules in rules.rs
  • Added many unit tests to ensure rules do what they're supposed to
  • Fixed is_set function and added unit test to make it works as expected

@supermaxiste
Copy link
Member Author

Addresses #5

@supermaxiste supermaxiste self-assigned this Jul 8, 2024
@supermaxiste supermaxiste marked this pull request as ready for review July 8, 2024 10:03
Copy link
Contributor

@gabyx gabyx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good job with the tests and rules in general. Before you start with the review read: It might more sense to sit together and pair-program this, which is where we both learn =).

There are some comments which need some discussion =).

Logic:

  • The eval_ function do their job, but have strange signature and there is some input we should go through together.
  • The serialization is of the rdf_types might still be a bit raw and can be niceified in another PR.

Style:

  • I am not sure what rust-fmt does, but I guess its not as hard on the newlines as it shoud be. Some parts in rules.rs are glued together which is not nice for the reader =). I try to show you what I mean while pair-programming this.

There is more... -> Metting

Entity::BlankNode(b) => Entity::BlankNode(self.pseudo_blank_node(&b)),
}
}
// private methods? Blanket implementations
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hint: Is this a comment? Otherwise remove.

//return l.clone();

fn pseudo_blank_node(&self, u: &BlankNode) -> BlankNode;
// return u.clone()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hint: remove

Suggested change
// return u.clone()

}
// private methods? Blanket implementations
fn pseudo_named_node(&self, t: &NamedNode) -> NamedNode;
//return t.clone();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//return t.clone();

//return t.clone();

fn pseudo_literal(&self, l: &Literal) -> Literal;
//return l.clone();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
//return l.clone();

impl Pseudonymize for DefaultHasher {
fn pseudo_named_node(&self, t: &NamedNode) -> NamedNode {
// We check for the last backslash in the IRI and add 1 to include the backslash
let prefix = &t.iri[0..t.iri.rfind('/').unwrap() + 1];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: What happens when there is no /. Good documented.
Should the function panic or gracefully ignore the not-found prefix?

suggetion: unwrap -> panic. maybe wrap this with expect("Expected to find a '<prefix>/...'")

otherwise: What we can and should look into is how to correctly split this: LINK
I assume rio does not provide and facility to deal with IRIs...?

src/rules.rs Outdated
Comment on lines 69 to 70
mask = eval_type_rule_named_node(false, n.clone(), mask, rules, type_map);
return mask;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mask = eval_type_rule_named_node(false, n.clone(), mask, rules, type_map);
return mask;
return eval_type_rule_named_node(false, n.clone(), mask, rules, type_map);

src/rules.rs Outdated
Comment on lines 85 to 86
mask |= TripleMask::OBJECT;
return mask;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
mask |= TripleMask::OBJECT;
return mask;
return mask | TripleMask::OBJECT;

Comment on lines +87 to +80
} else {
return mask;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
} else {
return mask;
}
}
return mask;

src/rules.rs Outdated
let mut type_map = HashMap::new();
type_map.insert("http://example.org/Alice".to_string(), "Person".to_string());
let mut mask = TripleMask::new();
mask = eval_type_rule_object(&object, mask, &type_map, &rules);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: I would rather go for a name match_rule_object which makes more sense, IMO. eval -> suggests you are already executing this rule.

src/rules.rs Outdated
} else {
return mask;
};
if rules.replace_values_of_subject_predicate.contains_key(subject_type) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hint: we need to pair program this 🤣 > Have some important input here. About nesting and glueing and
how the signature of this function should be =)

- added rstest for table driven tests.
@supermaxiste supermaxiste merged commit 4c8b5c4 into main Jul 10, 2024
7 checks passed
@supermaxiste supermaxiste deleted the feat/hash branch July 10, 2024 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants