Skip to content

Issue 114 word annotation - #119

Open
Teja-Sri-Surya wants to merge 36 commits into
Wikimedia-Suomi:mainfrom
Teja-Sri-Surya:issue-114-word-annotation
Open

Issue 114 word annotation#119
Teja-Sri-Surya wants to merge 36 commits into
Wikimedia-Suomi:mainfrom
Teja-Sri-Surya:issue-114-word-annotation

Conversation

@Teja-Sri-Surya

@Teja-Sri-Surya Teja-Sri-Surya commented Oct 26, 2025

Copy link
Copy Markdown
Contributor

Summary

Implements token/word-level diff tracking to visualize wikitext authorship across revisions.

Features

Annotation system:

  • Models: WordAnnotation and RevisionAnnotation
  • MediaWiki REST API diff processing
  • Tracks added/deleted/moved/modified text
  • Stable word IDs across revisions
  • Author attribution

Annotation engine:

  • Preserves original author on moves
  • Detects modifications and tracks previous IDs
  • Word/token diff processing
  • Supports annotating from any revision

Management commands:

  • annotate_article: Annotate article history with configurable revision ranges
  • get_annotated_revision: Retrieve and display annotation data (JSON, text, summary)

Web UI:

  • Page: /word-annotation/
  • Color coding by author
  • Author filtering dropdown
  • Stats: total words, unique authors, added words
  • Revision metadata

Technical details

  • Integrates MediaWiki REST API (/core/v1/revision/{from}/compare/{to})
  • Word-level tokenization and diff processing
  • Stable word IDs for cross-revision tracking
  • Indexed queries

Database schema:

  • WordAnnotation: word-level metadata
  • RevisionAnnotation: annotation status and metadata

Usage

# Annotate an article
python manage.py annotate_article 12345

# Get annotated revision
python manage.py get_annotated_revision 12345 67890 --output summary

UI access:
Open /word-annotation/ to visualize word-level authorship.

Closes #114

- Add revert detection check to autoreview system
- Implement @zache-fi's Superset approach for finding reviewed revisions
- Add change_tag_params to Superset query for revert detection
- Add comprehensive tests for revert detection functionality
- Add ENABLE_REVERT_DETECTION configuration setting
- Parse change tag parameters to extract reverted revision IDs
- Query MediaWiki database for previously reviewed content by SHA1

Fixes Wikimedia-Suomi#3 - Add check for already-reviewed reverted edits
 Complete LiftWing integration:
- Article validation using real MediaWiki API
- Revision history fetching (up to 50 revisions)
- LiftWing API integration with parallel requests
- Interactive Chart.js visualization
- Database models for caching
- Admin interface for new models
- Comprehensive error handling

 Performance optimization:
- ThreadPoolExecutor for parallel requests (10x faster)
- Batch processing for multiple revisions
- Timeout protection and error recovery

 Frontend features:
- Interactive line graph showing quality scores over time
- Revision history table with clickable Wikipedia diffs
- Real-time loading indicators and progress bar
- Support for multiple Wikipedia languages

This is a clean implementation without any unnecessary files.
 Added missing LiftWing functions:
- liftwing_page - Main LiftWing visualization page
- validate_article - Article validation using MediaWiki API
- fetch_revisions - Fetch article revision history
- fetch_liftwing_predictions - Parallel LiftWing API calls
- fetch_predictions - Single article prediction
- liftwing_models - Comprehensive ML models list

 Fixed issues:
- Removed merge conflict marker (>>>>>>> upstream/main)
- Added complete LiftWing integration
- Added parallel request optimization with ThreadPoolExecutor
- Added comprehensive error handling
- Added support for 6 ML models with full language support

 All functionality working:
- No syntax errors
- No linter errors
- Complete LiftWing feature implementation
@Teja-Sri-Surya
Teja-Sri-Surya force-pushed the issue-114-word-annotation branch from 6de885e to 1a104e4 Compare October 26, 2025 15:40
- Add revert detection check to autoreview system
- Implement @zache-fi's Superset approach for finding reviewed revisions
- Add change_tag_params to Superset query for revert detection
- Add comprehensive tests for revert detection functionality
- Add ENABLE_REVERT_DETECTION configuration setting
- Parse change tag parameters to extract reverted revision IDs
- Query MediaWiki database for previously reviewed content by SHA1

Fixes Wikimedia-Suomi#3 - Add check for already-reviewed reverted edits
…-Suomi#113)

- Created benchmark_superseded_additions Django management command
- Compares current superseded_additions check with REST API diff method
- Added superseded_additions.py check function with placeholder implementation
- Added context.py for CheckContext dataclass
- Fixed import conflicts and Unicode handling
- Command successfully runs and reports discrepancies with diff URLs

This tool helps evaluate the accuracy of superseded additions detection by:
- Running both the current method and REST API diff method on same revisions
- Surfacing discrepancies between the two approaches
- Providing review links for human verification
- Reporting agreement statistics

Usage:
  python manage.py benchmark_superseded_additions --limit 50
  python manage.py benchmark_superseded_additions --wiki fi
  python manage.py benchmark_superseded_additions --page-id 12345

Resolves Wikimedia-Suomi#113
…ection, and better tokenization

- Add WordAnnotation and RevisionAnnotation to Django admin
- Implement proper move detection in annotation engine
- Enhance tokenization to handle wikitext markup (templates, links, refs, HTML)
- Add comprehensive analysis document with all issues and fixes

Fixes for Issue Wikimedia-Suomi#114
…p only word annotation (Issue Wikimedia-Suomi#114)

Removed:
- Revert detection code (Issue Wikimedia-Suomi#3) - belongs in separate PR
- Benchmark command (Issue Wikimedia-Suomi#113) - already in PR Wikimedia-Suomi#133
- LiftWing feature - belongs in separate PR

Removed files:
- app/reviews/autoreview/checks/revert_detection.py
- app/reviews/tests/test_revert_detection.py
- app/reviews/management/commands/benchmark_superseded_additions.py
- app/templates/reviews/lift.html

Cleaned code:
- app/reviewer/settings.py (removed ENABLE_REVERT_DETECTION)
- app/reviews/urls.py (removed LiftWing URL patterns)

Note: views.py LiftWing functions will be removed during merge conflict resolution.
See CLEANUP_SUMMARY.md for remaining cleanup tasks.

This PR now focuses solely on Issue Wikimedia-Suomi#114 (Word Annotation System).
Merged changes from main branch:
- Added FlaggedRevsStatistics and ReviewActivity models
- Added admin classes for FlaggedRevsStatistics and ReviewActivity
- Added flaggedrevs-statistics API endpoints
- Added api_statistics_clear_and_reload endpoint

Kept word annotation features (Issue Wikimedia-Suomi#114):
- WordAnnotation and RevisionAnnotation models and admin
- Word annotation management commands
- Word annotation views and URLs

All conflicts resolved by keeping both sets of features.
- Added api_flaggedrevs_activity view
- Added flaggedrevs_statistics_page view
- Added corresponding URL patterns
- Complete integration with main branch features
@Teja-Sri-Surya

Copy link
Copy Markdown
Contributor Author

✅ PR #119 - Word Annotation System Ready

Complete implementation of Issue #114 with:

  • Word-level authorship tracking
  • Interactive visualization at /word-annotation/
  • Admin interface & API endpoints
  • Move detection algorithm

Test: Page ID 5935, Revision 1316772466 → 7,494 words displayed

All tests pass, ready for review! 🚀 @zache-fi @ademolaomosanya @ad-an-26
Screenshot 2025-10-28 203236
Screenshot 2025-10-28 203313

@ademolaomosanya

Copy link
Copy Markdown
Collaborator

✅ PR #119 - Word Annotation System Ready

Complete implementation of Issue #114 with:

  • Word-level authorship tracking
  • Interactive visualization at /word-annotation/
  • Admin interface & API endpoints
  • Move detection algorithm

Test: Page ID 5935, Revision 1316772466 → 7,494 words displayed

All tests pass, ready for review! 🚀 @zache-fi @ademolaomosanya @ad-an-26 Screenshot 2025-10-28 203236 Screenshot 2025-10-28 203313

Ah, got it! Nice work @Teja-Sri-Surya!
I was trying to navigate the changes earlier but couldn’t get the UI to run properly. I’ll pull the latest changes,that should help.

@ademolaomosanya

Copy link
Copy Markdown
Collaborator

@Teja-Sri-Surya
I have tested this PR locally, overall the endpoints are correctly wired, but I ran into some issues around the 404/400 responses for annotations.
for example, http://127.0.0.1:8000/api/annotations/words/?page_id=5935&revision_id=1316772466 returns a 404 (Not Found).
I used the UI with the page ID and revision ID above (5935, 1316772466).
Is there something I might be missing that could be causing this error?
Also, could you please share the steps you followed to get the UI shown above?

Screen.Recording.2025-10-29.at.07.52.00.mov

@ademolaomosanya ademolaomosanya added the ready for review Indicates the PR is complete and ready for maintainer review. label Oct 29, 2025
- Wrap long line in reviewer/settings.py (E501)
- Split long list_display in admin.py and clean imports (E501/F811)
- Use sha256 for stable word IDs (S324)
Teja-Sri-Surya added a commit to Teja-Sri-Surya/PendingChangesBot-ng that referenced this pull request Oct 31, 2025
…or PR Wikimedia-Suomi#119

- Remove duplicate helper functions (calculate_percentile, get_time_filter_cutoff, statistics_page)
- Remove duplicate LiftWing functions (liftwing_page, validate_article, fetch_revisions, fetch_liftwing_predictions, fetch_predictions, api_statistics_clear_and_reload)
- Remove redundant local imports of FlaggedRevsStatistics and ReviewActivity
- Add noqa comments for intentional try-except-pass blocks (S110)
- Fix line-length violations (E501) by wrapping long lines and adding noqa for very long language lists
- Remove unused variable data_series (F841)
- Fix import sorting (I001) and remove unused import
- Format code with ruff

All CI lint and security checks now pass.
Teja-Sri-Surya added a commit to Teja-Sri-Surya/PendingChangesBot-ng that referenced this pull request Nov 1, 2025
…or PR Wikimedia-Suomi#119

- Remove duplicate helper functions (calculate_percentile, get_time_filter_cutoff, statistics_page)
- Remove duplicate LiftWing functions (liftwing_page, validate_article, fetch_revisions, fetch_liftwing_predictions, fetch_predictions, api_statistics_clear_and_reload)
- Remove redundant local imports of FlaggedRevsStatistics and ReviewActivity
- Add noqa comments for intentional try-except-pass blocks (S110)
- Fix line-length violations (E501) by wrapping long lines and adding noqa for very long language lists
- Remove unused variable data_series (F841)
- Fix import sorting (I001) and remove unused import
- Format code with ruff

All CI lint and security checks now pass.
@Teja-Sri-Surya
Teja-Sri-Surya force-pushed the issue-114-word-annotation branch from 450ab7b to 51285f6 Compare November 1, 2025 01:33
- Fix whitespace in blank lines
- Sort imports in urls.py
- Format annotation engine and management commands
…iki data to statistics page

- Change snake_case to camelCase in api_flaggedrevs_statistics response (totalPages_ns0, reviewedPages_ns0, etc.)
- Change snake_case to camelCase in api_flaggedrevs_activity response (numberOfReviewers, numberOfReviews, etc.)
- Add wiki data context to flaggedrevs_statistics_page view to fix template rendering

Fixes test failures:
- test_api_statistics_with_specific_wiki
- test_api_statistics_single_wiki
- test_api_statistics_data_format
- test_statistics_page_includes_wikis
- Change pendingLag_average to pendingLagAverage
- Change number_of_reviewers to numberOfReviewers
- Change number_of_reviews to numberOfReviews
- Change number_of_pages to numberOfPages
- Change reviews_per_reviewer to reviewsPerReviewer

Fixes remaining test failures:
- test_api_statistics_data_format
- test_api_review_activity_data_format
- test_api_review_activity_with_specific_wiki
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready for review Indicates the PR is complete and ready for maintainer review.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Detecting Superseded Pending Changes ( Token/Word-Level Diff Tracking)

2 participants