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

Fully merge the Watson and Embeddings classification features #709

Merged
merged 22 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3858eca
Start moving classification feature functionality into the feature an…
dkotter Feb 6, 2024
6cc28ca
Move most of the Watson settings into the Feature class
dkotter Feb 6, 2024
412ee09
Start moving Embedding functionality over into the Feature class
dkotter Feb 7, 2024
2c19a65
Move more functionality from both NLU and Embeddings Providers
dkotter Feb 7, 2024
505dbd0
Get Classic Editor functionality working for Embeddings
dkotter Feb 7, 2024
db6f5f0
Get Classic Editor functionality working for Watson
dkotter Feb 7, 2024
05aea79
Ensure bulk actions for classification still work
dkotter Feb 7, 2024
610e61c
Fix a few bugs with bulk actions. Move some functions up to the featu…
dkotter Feb 7, 2024
6ac32ee
Fix our WP-CLI commands
dkotter Feb 7, 2024
19919fd
Ensure saving in the block editor triggers classification for both pr…
dkotter Feb 8, 2024
5425c45
Ensure that manually classifying works in the Block Editor for Watson
dkotter Feb 8, 2024
1b1b83f
Ensure that manually classifying works in the Block Editor for Embedd…
dkotter Feb 8, 2024
9dbd2bd
Ensure preview functionality is working
dkotter Feb 8, 2024
7edfa22
Fix unit tests and PHPCS issues
dkotter Feb 8, 2024
8748511
Fix fatal error
dkotter Feb 8, 2024
ef918f3
Fix E2E tests and bugs it found
dkotter Feb 9, 2024
b2cde57
Ensure we only limit bulk action based on post status for features th…
dkotter Feb 16, 2024
b0b3146
When getting our list of supported taxonomies, ensure we filter out a…
dkotter Feb 16, 2024
f6b8e56
Exclude the uncategorized term
dkotter Feb 16, 2024
ee21bcb
Fix PHPCS error and fix tests
dkotter Feb 16, 2024
f4813d5
Fix Cursor Pointer Not Functional for Taxonomy Label on IBM Watson NL…
iamdharmesh Feb 19, 2024
420d2f0
Exclude post format taxonomy.
iamdharmesh Feb 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 35 additions & 2 deletions includes/Classifai/Admin/BulkActions.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function register_language_processing_hooks() {
continue;
}

foreach ( $settings['post_types'] as $key => $post_type ) {
foreach ( $settings['post_types'] as $post_type ) {
add_filter( "bulk_actions-edit-$post_type", [ $this, 'register_language_processing_actions' ] );
add_filter( "handle_bulk_actions-edit-$post_type", [ $this, 'language_processing_actions_handler' ], 10, 3 );

Expand All @@ -107,6 +107,10 @@ public function register_language_processing_actions( array $bulk_actions ): arr
continue;
}

if ( ! in_array( get_post_type(), $feature->get_supported_post_types(), true ) ) {
continue;
}

$bulk_actions[ $feature::ID ] = $feature->get_label();

switch ( $feature::ID ) {
Expand Down Expand Up @@ -153,7 +157,25 @@ function ( $feature ) {
foreach ( $post_ids as $post_id ) {
switch ( $doaction ) {
case Classification::ID:
( new Classification() )->run( $post_id );
// Check to see if processing is disabled and overwrite that.
// Since we are manually classifying, we want to force this.
$classification_enabled = get_post_meta( $post_id, '_classifai_process_content', true );
if ( 'yes' !== $classification_enabled ) {
update_post_meta( $post_id, '_classifai_process_content', 'yes' );
}

$classification = new Classification();
$classify_results = $classification->run( $post_id, 'classify' );

// Ensure the processing value is changed back to what it was.
if ( 'yes' !== $classification_enabled ) {
update_post_meta( $post_id, '_classifai_process_content', 'no' );
}

if ( ! empty( $classify_results ) && ! is_wp_error( $classify_results ) ) {
$classification->save( $post_id, $classify_results );
}

$action = $doaction;
break;

Expand Down Expand Up @@ -283,6 +305,17 @@ public function register_language_processing_row_action( array $actions, \WP_Pos
continue;
}

if ( ! in_array( get_post_type(), $feature->get_supported_post_types(), true ) ) {
continue;
}

if (
Classification::ID === $feature::ID &&
! in_array( get_post_status(), $feature->get_supported_post_statuses(), true )
) {
continue;
}

switch ( $feature::ID ) {
case Classification::ID:
$actions[ Classification::ID ] = sprintf(
Expand Down
53 changes: 35 additions & 18 deletions includes/Classifai/Command/ClassifaiCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,17 @@ public function post( $args = [], $opts = [] ) {
$post_ids = $this->get_posts_to_classify( $opts );
}

$total = count( $post_ids );
$classifier = new PostClassifier();
$limit = $opts['limit'];
$link = $opts['link'];
$link = filter_var( $link, FILTER_VALIDATE_BOOLEAN );
$feature = new Classification();
$provider = $feature->get_feature_provider_instance();

if ( Embeddings::ID !== $provider::ID ) {
\WP_CLI::error( 'This command is only available for the IBM Watson Provider' );
}

$total = count( $post_ids );
$limit = $opts['limit'];
$link = $opts['link'];
$link = filter_var( $link, FILTER_VALIDATE_BOOLEAN );

if ( ! empty( $total ) ) {
if ( ! empty( $limit ) ) {
Expand All @@ -83,15 +89,18 @@ public function post( $args = [], $opts = [] ) {

$progress_bar->tick();

if ( $link ) {
$output = $classifier->classify_and_link( $post_id, $opts );
$results = $feature->run( $post_id, 'classify' );

if ( is_wp_error( $results ) ) {
$errors[ $post_id ] = $results;
}

if ( is_wp_error( $output ) ) {
$errors[ $post_id ] = $output;
if ( ! empty( $results ) && ! is_wp_error( $results ) ) {
if ( $link ) {
$feature->save( $post_id, $results );
} else {
$this->print( $results, $post_id );
}
} else {
$output = $classifier->classify( $post_id, $opts );
$this->print( $output, $post_id );
}
}

Expand Down Expand Up @@ -963,8 +972,8 @@ public function embeddings( $args = [], $opts = [] ) {
$embeddings = new Embeddings( false );
$opts = wp_parse_args( $opts, $defaults );
$opts['per_page'] = (int) $opts['per_page'] > 0 ? $opts['per_page'] : 100;
$allowed_post_types = $embeddings->supported_post_types();
$allowed_post_status = $embeddings->supported_post_statuses();
$allowed_post_types = $feature->get_supported_post_types();
$allowed_post_status = $feature->get_supported_post_statuses();

$count = 0;
$errors = 0;
Expand Down Expand Up @@ -1015,9 +1024,13 @@ public function embeddings( $args = [], $opts = [] ) {

foreach ( $posts as $post_id ) {
if ( ! $dry_run ) {
$result = $feature->run( $post_id );
$results = $feature->run( $post_id, 'classify' );

if ( is_wp_error( $result ) ) {
if ( ! empty( $results ) && ! is_wp_error( $results ) ) {
$feature->save( $post_id, $results );
}

if ( is_wp_error( $results ) ) {
\WP_CLI::error( sprintf( 'Error while processing item ID %s', $post_id ), false );
++$errors;
}
Expand Down Expand Up @@ -1063,9 +1076,13 @@ public function embeddings( $args = [], $opts = [] ) {
}

if ( ! $dry_run ) {
$result = $feature->run( $post_id );
$results = $feature->run( $post_id, 'classify' );

if ( is_wp_error( $result ) ) {
if ( ! empty( $results ) && ! is_wp_error( $results ) ) {
$feature->save( $post_id, $results );
}

if ( is_wp_error( $results ) ) {
\WP_CLI::error( sprintf( 'Error while processing item ID %s', $post_id ), false );
++$errors;
}
Expand Down
Loading
Loading