<commit_before># -*- coding: utf-8; -*-
#
# This file is part of Superdesk.
#
# Copyright 2013, 2014 Sourcefabric z.u. and contributors.
#
# For the full copyright and license information, please see the
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license

from superdesk.activity import add_activity
from eve.utils import ParsedRequest
from flask import g

from superdesk.emails import send_user_mentioned_email

import re
import superdesk


def get_mentions(text):
    """
    Returns the names of desks and users from a given text
    User names starts with '@' and desk names starts with '#'
    """
    user_pattern = re.compile("(^|\s)\@([a-zA-Z0-9-_.]\w+)")
    desk_pattern = re.compile("(^|\s)\#([a-zA-Z0-9-_.]\w+)")
    raw_user_names = set(username for match in re.finditer(user_pattern, text) for username in match.groups())
    raw_desk_names = set(deskname for match in re.finditer(desk_pattern, text) for deskname in match.groups())
    desk_names = [d.replace('_', ' ') for d in raw_desk_names if d.strip()]
    user_names = [u for u in raw_user_names if u.strip()]
    return user_names, desk_names


def send_email_to_mentioned_users(doc, mentioned_users, origin):
    prefs_service = superdesk.get_resource_service('preferences')
    recipients = []
    for user in mentioned_users:
        send_email = prefs_service.email_notification_is_enabled(user_id=user)
        if send_email:
            user_doc = superdesk.get_resource_service('users').find_one(req=None, _id=user)
            recipients.append(user_doc['email'])
    if recipients:
        username = g.user.get('display_name') or g.user.get('username')
        url = '{}/#/authoring/{}?comments={}'.format(origin, doc['item'], doc['_id'])<commit_msg>fix(server: comments: mentions): update authoring link in the mail<commit_after># -*- coding: utf-8; -*-
#
# This file is part of Superdesk.
#
# Copyright 2013, 2014 Sourcefabric z.u. and contributors.
#
# For the full copyright and license information, please see the
# AUTHORS and LICENSE files distributed with this source code, or
# at https://www.sourcefabric.org/superdesk/license

from superdesk.activity import add_activity
from eve.utils import ParsedRequest
from flask import g

from superdesk.emails import send_user_mentioned_email

import re
import superdesk


def get_mentions(text):
    """
    Returns the names of desks and users from a given text
    User names starts with '@' and desk names starts with '#'
    """
    user_pattern = re.compile("(^|\s)\@([a-zA-Z0-9-_.]\w+)")
    desk_pattern = re.compile("(^|\s)\#([a-zA-Z0-9-_.]\w+)")
    raw_user_names = set(username for match in re.finditer(user_pattern, text) for username in match.groups())
    raw_desk_names = set(deskname for match in re.finditer(desk_pattern, text) for deskname in match.groups())
    desk_names = [d.replace('_', ' ') for d in raw_desk_names if d.strip()]
    user_names = [u for u in raw_user_names if u.strip()]
    return user_names, desk_names


def send_email_to_mentioned_users(doc, mentioned_users, origin):
    prefs_service = superdesk.get_resource_service('preferences')
    recipients = []
    for user in mentioned_users:
        send_email = prefs_service.email_notification_is_enabled(user_id=user)
        if send_email:
            user_doc = superdesk.get_resource_service('users').find_one(req=None, _id=user)
            recipients.append(user_doc['email'])
    if recipients:
        username = g.user.get('display_name') or g.user.get('username')
        url = '{}/#/workspace?item={}&action=edit&comments={}'.format(origin, doc['item'], doc['_id'])
{'fraction_non_alphanumeric': 0.12431842966194111, 'fraction_numerical': 0.007088331515812432, 'mean_word_length': 4.026027397260274, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7542011', 'n_tokens_mistral': 1205, 'n_tokens_neox': 1169, 'n_words': 315}