Skip to content

Commit

Permalink
refactor: use a lookup for reasons
Browse files Browse the repository at this point in the history
  • Loading branch information
andylolz committed May 19, 2024
1 parent 6071f79 commit 111a084
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 21 deletions.
28 changes: 20 additions & 8 deletions output/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,18 @@ Proposed [Twitter community notes](https://twitter.com/i/communitynotes/download
*/
const langLookup = {'am': 'Amharic', 'ar': 'Arabic', 'bg': 'Bulgarian', 'bn': 'Bengali', 'bo': 'Tibetan', 'bs': 'Bosnian', 'ca': 'Catalan', 'ckb': 'Sorani Kurdish', 'cs': 'Czech', 'cy': 'Welsh', 'da': 'Danish', 'de': 'German', 'dv': 'Maldivian', 'el': 'Greek', 'en': 'English', 'es': 'Spanish', 'et': 'Estonian', 'eu': 'Basque', 'fa': 'Persian', 'fi': 'Finnish', 'fr': 'French', 'gu': 'Gujarati', 'hi': 'Hindi', 'hi-Latn': 'Latinized Hindi', 'hr': 'Croatian', 'ht': 'Haitian Creole', 'hu': 'Hungarian', 'hy': 'Armenian', 'in': 'Indonesian', 'is': 'Icelandic', 'it': 'Italian', 'iw': 'Hebrew', 'ja': 'Japanese', 'ka': 'Georgian', 'km': 'Khmer', 'kn': 'Kannada', 'ko': 'Korean', 'lo': 'Lao', 'lt': 'Lithuanian', 'lv': 'Latvian', 'ml': 'Malayalam', 'mr': 'Marathi', 'my': 'Burmese', 'ne': 'Nepali', 'nl': 'Dutch', 'no': 'Norwegian', 'or': 'Oriya', 'pa': 'Panjabi', 'pl': 'Polish', 'ps': 'Pashto', 'pt': 'Portuguese', 'ro': 'Romanian', 'ru': 'Russian', 'sd': 'Sindhi', 'si': 'Sinhala', 'sk': 'Slovak', 'sl': 'Slovenian', 'sr': 'Serbian', 'sv': 'Swedish', 'ta': 'Tamil', 'te': 'Telugu', 'th': 'Thai', 'tl': 'Tagalog', 'tr': 'Turkish', 'ug': 'Uyghur', 'uk': 'Ukrainian', 'ur': 'Urdu', 'vi': 'Vietnamese', 'zh-CN': 'Simplified Chinese', 'zh-TW': 'Traditional Chinese', 'zh': 'Chinese', 'art': 'X', 'qam': 'X', 'qct': 'X', 'qht': 'X', 'qme': 'X', 'qst': 'X', 'und': 'X', 'zxx': 'X'}

const reasonsLookup = {1: "Factual error", 2: "Manipulated media", 3: "Missing important context", 4: "Other", 5: "Outdated information", 6: "Satire", 7: "Unverified claim as fact"}

const getReasons = function (values) {
if (!Array.isArray(values)) {
return values;
}
return values.map(v => reasonsLookup[v]).join(", ");
}

const includesReason = function (reason) {
return function (rowData, rowIdx) {
return rowData['reasons'].split(', ').includes(reason);
return rowData['reasons'].includes(reason);
}
}

Expand Down Expand Up @@ -102,35 +111,38 @@ Proposed [Twitter community notes](https://twitter.com/i/communitynotes/download
},
{
data: 'reasons',
render: function (data, type, row, meta) {
return getReasons(data);
},
searchPanes: {
options: [
{
label: 'Factual error',
value: includesReason('Factual error'),
value: includesReason(1),
},
{
label: 'Manipulated media',
value: includesReason('Manipulated media'),
value: includesReason(2),
},
{
label: 'Missing important context',
value: includesReason('Missing important context'),
value: includesReason(3),
},
{
label: 'Other',
value: includesReason('Other'),
value: includesReason(4),
},
{
label: 'Outdated information',
value: includesReason('Outdated information'),
value: includesReason(5),
},
{
label: 'Satire',
value: includesReason('Satire'),
value: includesReason(6),
},
{
label: 'Unverified claim as fact',
value: includesReason('Unverified claim as fact'),
value: includesReason(7),
}
]
}
Expand Down
26 changes: 13 additions & 13 deletions x_notes/notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ def format_url(match: re.Match) -> str:


reasons_lookup = {
"misleadingOther": "Other",
"misleadingFactualError": "Factual error",
"misleadingManipulatedMedia": "Manipulated media",
"misleadingOutdatedInformation": "Outdated information",
"misleadingMissingImportantContext": "Missing important context",
"misleadingUnverifiedClaimAsFact": "Unverified claim as fact",
"misleadingSatire": "Satire",
# "notMisleadingOther": "Other",
# "notMisleadingFactuallyCorrect": "Factually correct",
# "notMisleadingOutdatedButNotWhenWritten": "Outdated (but not when written)",
# "notMisleadingClearlySatire": "Clearly satire",
# "notMisleadingPersonalOpinion": "Personal opinion",
"misleadingFactualError": 1,
"misleadingManipulatedMedia": 2,
"misleadingMissingImportantContext": 3,
"misleadingOther": 4,
"misleadingOutdatedInformation": 5,
"misleadingSatire": 6,
"misleadingUnverifiedClaimAsFact": 7,
# "notMisleadingClearlySatire": 8,
# "notMisleadingFactuallyCorrect": 9,
# "notMisleadingOther": 10,
# "notMisleadingOutdatedButNotWhenWritten": 11,
# "notMisleadingPersonalOpinion": 12,
}


Expand All @@ -60,7 +60,7 @@ def get_notes(notes: dict[str, dict[str, Any]]) -> dict[str, dict[str, Any]]:
if note_id in notes:
del notes[note_id]
continue
reasons = ", ".join([v for k, v in reasons_lookup.items() if bool(int(row[k]))])
reasons = [v for k, v in reasons_lookup.items() if bool(int(row[k]))]
note = notes.get(note_id, {})
note.update(
{
Expand Down

0 comments on commit 111a084

Please sign in to comment.