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

Rule based tags #1478

Merged
merged 32 commits into from
Dec 6, 2015
Merged

Rule based tags #1478

merged 32 commits into from
Dec 6, 2015

Conversation

K-Phoen
Copy link
Contributor

@K-Phoen K-Phoen commented Oct 11, 2015

As described in #1477, here is my PoC for a rule-based automatic tagging.

It rules engine is RulerZ and I created a new tab in the configuration panel to manage the tagging rules. It's a quick draft but at least it allows us to create rules and test them:

capture d ecran de 2015-10-11 18-41-05

It's really a WIP so there are no tests, validation for the rules or help about the DSL used for the rules.

If you like the overall direction of this feature, I'll finish my PR :)

Note: there are a lot of additions but it's mainly the composer.lock file. Also, reading the PR commit-by-commit should be easier.

Updated screenshot:

image

@K-Phoen K-Phoen changed the title Rule based tags [WIP] Rule based tags Oct 11, 2015
@tcitworld
Copy link
Member

Impressive ! Can you fix the Travis Error (it's just a use Doctrine\Common\Collections\ArrayCollection; missing in Entity/Config.php ).

@K-Phoen
Copy link
Contributor Author

K-Phoen commented Oct 11, 2015

Should be better now :)

@@ -54,7 +54,8 @@
"lexik/form-filter-bundle": "~4.0",
"j0k3r/graby": "~1.0",
"friendsofsymfony/user-bundle": "dev-master",
"friendsofsymfony/oauth-server-bundle": "^1.4@dev"
"friendsofsymfony/oauth-server-bundle": "^1.4@dev",
"kphoen/rulerz-bundle": "dev-master"
Copy link
Member

Choose a reason for hiding this comment

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

Can't we use a tagged version instead?

@j0k3r
Copy link
Member

j0k3r commented Oct 12, 2015

This a good start! I wasn't aware that this bundle will include all that stuff from Hoa project 😳

Anyway, apart my first little comments:

  • a better kind of FAQ could be great for novice people, something like "Let assume you want to tag all BLABLA when BLABLA happen, you should put THAT in THIS field", etc ...
  • don't forget unit test on StringToListTransformer & RuleBasedTagger
  • did you validate the rule somewhere when adding it? I mean, what if a user set an invalid rule (let's assume it's possible) will it be notified if the rule is wrong?

@K-Phoen
Copy link
Contributor Author

K-Phoen commented Oct 14, 2015

This a good start! I wasn't aware that this bundle will include all that stuff from Hoa project 😳

My bad, I didn't properly introduce RulerZ :)
This library primarily adds a layer on top of Hoa\Ruler allowing us to use rules on objects as well as any other data-source, that's why requiring RulerZ also requires a few libraries from the Hoa Project.
RulerZ also goes a step further than Hoa\Ruler: it really compiles rules instead of having to evaluate on-the-fly an abstract representation of the rule.

a better kind of FAQ could be great for novice people, something like "Let assume you want to tag all BLABLA when BLABLA happen, you should put THAT in THIS field", etc ...

Agreed. I just wrote a list of the usable variables so that you could see the possibilities of the feature. I'll try to write a proper FAQ once the code is done :)

don't forget unit test on StringToListTransformer & RuleBasedTagger

Done for StringToListTransformer, I will write tests for RuleBasedTagger later.

did you validate the rule somewhere when adding it? I mean, what if a user set an invalid rule (let's assume it's possible) will it be notified if the rule is wrong?

It was on my roadmap. I committed a first version of the validator today but it's really a naïve one: it just validates the syntax. For instance, if you use an undefined variable no validation error will be triggered. I'll improve the validator to detect these errors.

@nicosomb
Copy link
Member

I just gave a try 👍

Do you think that it's possible to have a command to assign these tags to existing articles?

@K-Phoen
Copy link
Contributor Author

K-Phoen commented Oct 15, 2015

I also had this idea in mind, that's why I used RulerZ instead of Hoa\Ruler.

While Hoa\Ruler only works on an object (in our case, an Entry), RulerZ can fetch all entries matching a given rule directly from the database.

So yeah, writing a command/controller to tag existing articles should be easy :)

@nicosomb
Copy link
Member

Nice.

Don't forget to give availability to remove rule.
I created a new rule and all seems to be broken. My rule if « content like "%basket%" » then tag as « basket » (some doc will be necessary ;-) because I'm sure it's not the good syntax ), and I can't save a new entry.

@K-Phoen
Copy link
Contributor Author

K-Phoen commented Oct 15, 2015

Yep, there is still some work to be done on the validation. Also, I'll make sure that even if the automatic tagging fails it does not prevent the user to add new entries.

@K-Phoen
Copy link
Contributor Author

K-Phoen commented Oct 15, 2015

Thanks for your feedback btw 👍

@K-Phoen
Copy link
Contributor Author

K-Phoen commented Oct 31, 2015

I implemented a better validator for the tagging rules and also provided a way to delete them.
There is also a wallabag:tag:all command to tag all entries for a given user according to its tagging rules.

There is still some documentation about the rules to be written. You wanted that on a separate page? Do you already have one?

use KPhoen\RulerZBundle\Validator\Constraints as RulerZAssert;

/**
* Config.
Copy link
Member

Choose a reason for hiding this comment

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

Bad copy/paste?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep.

@j0k3r
Copy link
Member

j0k3r commented Oct 31, 2015

Looks good 😄

About the documentation your are talking about, is that the FAQ displayed below the tagging page or something better which need to be in the documentation of wallabag?
Maybe you can write a small FAQ in the tagging page (like I said in a previous comment: Let assume you want to tag all BLABLA when BLABLA happen, you should put THAT in THIS field)

And you can add a better documentation in our doc, which is now part of the repo since #1495. Maybe you'll have to rebase your PR to get that changes.

@j0k3r j0k3r added this to the 2.0.0 milestone Oct 31, 2015
@nicosomb
Copy link
Member

nicosomb commented Nov 2, 2015

Conflict with v2 branch. Will try this PR maybe this evening.

@nicosomb
Copy link
Member

Something like title matches "basket" would be enough? The matches operator would work like the stripos PHP function, it would return true only if there is an exact match.

Yes 👍

I also tried to reproduce your bug but I couldn't…

Will retry

wallabag:tag:all

Oh nice, I didn't see this feature! What do you think having a button: "tag all the previous entries"?

@j0k3r
Copy link
Member

j0k3r commented Nov 13, 2015

What do you think having a button: "tag all the previous entries"?

Depending on the number of entries for the current user, it could take long time to accomplish ..

@K-Phoen
Copy link
Contributor Author

K-Phoen commented Nov 13, 2015

I added the matches operator :)

@nicosomb
Copy link
Member

<3 (just need documentation about this new operator maybe)

$pattern = sprintf("'%%%s%%'", substr($pattern, 1, -1));
}

return sprintf('UPPER(%s) LIKE UPPER(%s)', $subject, $pattern);
Copy link
Member

Choose a reason for hiding this comment

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

Is it working on MySQL, PostGres & SQLite ? Maybe a working test for the matches keyword could be a good idea.

@K-Phoen
Copy link
Contributor Author

K-Phoen commented Nov 13, 2015

<3 (just need documentation about this new operator maybe)

Oops, my bad, I forgot :)
I'll add it tonight.

Is it working on MySQL, PostGres & SQLite ? Maybe a working test for the matches keyword could be a good idea.

It does. I'll add a test.


namespace Wallabag\CoreBundle\Operator\PHP;

class Matches
Copy link
Member

Choose a reason for hiding this comment

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

Could you explain what these classes are used for (both Operator\Doctrine\Matches & Operator\Doctrine\PHP) ?
In the context of your PR, we can guess but when it will be inside the project, it won't be that easy to guess

@K-Phoen
Copy link
Contributor Author

K-Phoen commented Nov 15, 2015

PHPdoc added, matches operator described in the FAQ and a little test was written :)

$entry = $em
->getRepository('WallabagCoreBundle:Entry')
->findOneByUrl($url);
$this->assertCount(1, $entry->getTags());
Copy link
Member

Choose a reason for hiding this comment

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

Could you just assert that the only tag for this entry is actually wallabag, as per the TaggingRule.

@j0k3r
Copy link
Member

j0k3r commented Nov 16, 2015

I think we are really close to get this merged 🚀
Thanks for the hard work and for taking care of all the feedback we provided!

</div>
</div>
</div>

{% if is_granted('ROLE_SUPER_ADMIN') %}
<div id="set5" class="col s12">
Copy link
Member

Choose a reason for hiding this comment

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

It might be a side effect of your change (and some rebase) but could you set set6 here instead of set5? Because we have 2 set5 in the page and it breaks the layout because, if user is super admin, Add a user will always be displayed.

@K-Phoen
Copy link
Contributor Author

K-Phoen commented Nov 29, 2015

I found some time to fix the tests, they're green now 🎉
Is there anything left to do before this PR is merged?

Anyway, thanks for all the valuable feedbacks you guys provided throughout this PR. Keep up the good work 👍

@tcitworld
Copy link
Member

Note for later : Think on how to export rules from one installation to another.

@K-Phoen
Copy link
Contributor Author

K-Phoen commented Nov 30, 2015

Both rules and tags can be represented as plain text so that should not be difficult :)

@j0k3r j0k3r changed the title [WIP] Rule based tags Rule based tags Dec 6, 2015
@j0k3r
Copy link
Member

j0k3r commented Dec 6, 2015

@K-Phoen Huge thank to you for that 👍

j0k3r added a commit that referenced this pull request Dec 6, 2015
@j0k3r j0k3r merged commit a7f1921 into wallabag:v2 Dec 6, 2015
@Hywan
Copy link

Hywan commented Dec 6, 2015

👍 \o/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants