Exemple #1
0
def len_match(s1, s2, ret):

    s1_ = s1.split()
    s2_ = s2.split()
    s1_wt = utils.get_tag(s1)
    s2_wt = utils.get_tag(s2)

    # How [do | can | will] [you | I | we] [verb] ~ ?
    if s1_wt[1][1] in ['VBP','VB','MD'] and s2_wt[1][1] in ['VBP','VB','MD'] and\
    s1_wt[3][1] == s2_wt[3][1] == 'VB' and\
    s1_wt[2][1] == s2_wt[2][1] == 'PRP':
        ret += '-vsv'

        # head 3 words match!!!
        if s1_[:3] == s2_[:3]:
            ret += '-h3'
            return ret

        # head 2 words match!!!
        elif s1_[:2] == s2_[:2]:
            ret += '-h2'
            return ret

        elif s1_[2:] == s2_[2:]:
            """
            s1_ = 'How can you improve intelligence ?'.split()
            s2_ = 'How do you improve intelligence ?'.split()
            """
            return ret + '1'

        elif s1_[1] == s2_[1] and s1_[3:] == s2_[3:]:
            """
            s1_ = 'How do I improve intelligence ?'.split()
            s2_ = 'How do you improve intelligence ?'.split()
            """
            return ret + '2'

        elif s1_[3:] == s2_[3:]:
            """
            s1_ = 'How can I improve intelligence ?'.split()
            s2_ = 'How do you improve intelligence ?'.split()
            """
            return ret + '12'
        else:
            return ret + 'N'
    else:
        ret += '-oth'
        return ret
Exemple #2
0
def get_top_words(filepath):
    noun_to_count = defaultdict(int)
    adj_to_count = defaultdict(int)
    all_to_count = defaultdict(int)

    if os.path.isfile("all_to_count.pickle"):
        all_to_count, noun_to_count, adj_to_count = pickle.load(
            open("all_to_count.pickle", "rb"))
        return noun_to_count, adj_to_count, all_to_count

    articles, _ = LoadArticles(filepath)
    for a in articles:
        words = a.split()
        for word in words:
            tag = get_tag(word)
            if not tag:
                all_to_count[word] += 1
                continue
            if "NOUN" in tag:
                noun_to_count[word] += 1
            elif "ADJF" in tag:
                adj_to_count[word] += 1
            all_to_count[word] += 1
    pickle.dump((all_to_count, noun_to_count, adj_to_count),
                open("all_to_count.pickle", "wb"))
    return noun_to_count, adj_to_count, all_to_count
Exemple #3
0
def find_best_noun(s):
    ix_best = s.index('best')
    wt = utils.get_tag(s[ix_best:])

    if ' to ' in s:
        ix_TO = min([i for i, (w, t) in enumerate(wt) if t == 'TO'])
    else:
        ix_TO = len(wt)

    ix_INs = [i for i, (w, t) in enumerate(wt) if t == 'IN']
    if len(ix_INs) != 0:
        ix_IN = min(ix_INs)
    else:
        ix_IN = len(wt)

    if ix_TO != ix_IN:
        ix_min = min(ix_TO, ix_IN)
        return wt[ix_min - 1][0]

    sw_NN = False
    for w, t in wt:
        if 'NN' in t:
            sw_NN = True
        if sw_NN:
            if 'NN' in t:
                noun = w
            else:
                return noun
        else:
            continue
    return
Exemple #4
0
	def zero_group( self ) :
		parent = self.getParent().getParent()
		d = settings.name_string_delimeter
		n = utils.get_tag( 'zero' )
		if( parent.name().rsplit( d, 1 )[-1] == n ) :
			return parent
		else :
			utils.err( 'Cannot find %s group for %s' % ( n, self ) )
			return False
Exemple #5
0
def get_VO(s):
    """
    """

    verb = obje = None

    if s.startswith('How') and len(s.split()) > 5:
        wt = utils.get_tag(s)
        # How can I ~
        # How do you ~
        if wt[1][1] in ['VBP', 'WRB', 'VB', 'MD'
                        ] and wt[2][1] == 'PRP' and 'VB' in wt[3][1]:
            verb = wt[3][0]
            obje = utils.find_noun_after_prep(verb, s, False)

            return verb, obje
        return verb, obje

    elif s.startswith('Is it possible to to') and len(s.split()) > 5:
        s_ = s.split()
        ix = s_.index('to') + 1
        verb = s_[ix]
        obje = utils.find_noun_after_prep(verb, s, False)

        return verb, obje

    elif (' ways to ' in s or ' way to ' in s) and len(s.split()) > 5:
        s_ = s.split()
        ix = s_.index('to') + 1
        verb = s_[ix]
        obje = utils.find_noun_after_prep(verb, s, False)

        return verb, obje

    if len(s.split()) > 3:
        wt = utils.get_tag(s)
        if wt[0][1] in ['MD'] and wt[1][1] == 'PRP' and 'VB' in wt[2][1]:
            verb = wt[2][0]
            obje = utils.find_noun(wt)

            return verb, obje

    return verb, obje
Exemple #6
0
async def on_member_update(before, after):
    channel = discord.utils.get(after.guild.channels, name='general')
    guild = get_guild_by_name(client, GUILD)
    members = [get_member_by_tag(guild, tag.value) for tag in SendGreetingTag]
    greeting_tag_list = [tag.value for tag in SendGreetingTag]
    activity_tag_list = [tag.value for tag in ActivityTag]

    if after.guild == guild:
        if before.status == Status.offline and after.status == Status.online:
            print("{} has gone {}.".format(after.name, after.status))
            if get_tag(after) in greeting_tag_list:
                await after.create_dm()
                await after.dm_channel.send(f'Te-a chemat cineva?! 😠')

        if after.activity is not None and after.activity.type == discord.ActivityType.playing:
            if "league of legends" in str(after.activity.name).lower(
            ) and get_tag(after) in activity_tag_list:
                await after.create_dm()
                await after.dm_channel.send(
                    f'Iar te joci LoL? Mai bine șterge-l...')
            if "warframe" in str(after.activity.name).lower() and get_tag(
                    after) == Tag.ANDREI.value:
                await after.create_dm()
                await after.dm_channel.send(
                    f'O să te joci Warframe și după ce mori, nu?')
            if "league of legends" in str(after.activity.name).lower(
            ) and get_tag(after) == Tag.ME.value:
                """await after.create_dm()
                await after.dm_channel.send(
                    f'/tts Iar te joci LoL? Mai bine șterge-l...'
                )"""
                if channel:
                    await channel.send(
                        f'{after.mention} is playing {after.activity.name} again.....'
                    )
        elif before.activity is not None and after.activity is None:
            if get_tag(after) in activity_tag_list:
                await after.create_dm()
                await after.dm_channel.send(
                    f'Ce faci? Nu ți-e rușine să nu te mai joci?!')
Exemple #7
0
 def setUp(self):
     fss.remove_tree(settings.MEDIA_ROOT)
     check_permissions()
     set_site(self.live_server_url)
     
     self.browser = Browser()
     self.browser.visit(self.live_server_url)
     
     login_url = settings.LOGIN_URL
     self.browser.click_link_by_partial_href(login_url)
     
     username = '******'
     password = '******'
     create_user(username)
     login(
         self.browser,
         username,
         password,
     )
     
     upload_url = reverse('documents.views.add_document')
     self.browser.click_link_by_partial_href(upload_url)
     
     source = 'local'
     docfile = get_abs_path('doctest.pdf')
     language = 'eng'
     public = True
     title = 'test'
     notes = 'test notes'
     upload(
         self.browser,
         source,
         docfile,
         language,
         public,
         title,
         notes,
     )
     
     self.browser.is_element_not_present_by_value('ready', 10)
     
     tag = 'tag'
     add_tag(
         self.browser,
         tag,
     )
     
     self.tag = tag
     self.tag_obj = get_tag(tag)
Exemple #8
0
    def setUp(self):
        fss.remove_tree(settings.MEDIA_ROOT)
        check_permissions()
        set_site(self.live_server_url)

        self.browser = Browser()
        self.browser.visit(self.live_server_url)

        login_url = settings.LOGIN_URL
        self.browser.click_link_by_partial_href(login_url)

        username = '******'
        password = '******'
        create_user(username)
        login(
            self.browser,
            username,
            password,
        )

        upload_url = reverse('documents.views.add_document')
        self.browser.click_link_by_partial_href(upload_url)

        source = 'local'
        docfile = get_abs_path('doctest.pdf')
        language = 'eng'
        public = True
        title = 'test'
        notes = 'test notes'
        upload(
            self.browser,
            source,
            docfile,
            language,
            public,
            title,
            notes,
        )

        self.browser.is_element_not_present_by_value('ready', 10)

        tag = 'tag'
        add_tag(
            self.browser,
            tag,
        )

        self.tag = tag
        self.tag_obj = get_tag(tag)
Exemple #9
0
def tagged_object_list(request, queryset_or_model=None, tag=None,
        related_tags=False, related_tag_counts=True, **kwargs):
    """
    A thin wrapper around
    ``django.views.generic.list_detail.object_list`` which creates a
    ``QuerySet`` containing instances of the given queryset or model
    tagged with the given tag.

    In addition to the context variables set up by ``object_list``, a
    ``tag`` context variable will contain the ``Tag`` instance for the
    tag.

    If ``related_tags`` is ``True``, a ``related_tags`` context variable
    will contain tags related to the given tag for the given model.
    Additionally, if ``related_tag_counts`` is ``True``, each related
    tag will have a ``count`` attribute indicating the number of items
    which have it in addition to the given tag.
    """

    from models import Tag, TaggedItem
    from utils import get_tag, get_queryset_and_model


    if queryset_or_model is None:
        try:
            queryset_or_model = kwargs.pop('queryset_or_model')
        except KeyError:
            raise AttributeError(_('tagged_object_list must be called with a queryset or a model.'))

    if tag is None:
        try:
            tag = kwargs.pop('tag')
        except KeyError:
            raise AttributeError(_('tagged_object_list must be called with a tag.'))

    tag_instance = get_tag(tag)
    if tag_instance is None:
        raise Http404(_('No Tag found matching "%s".') % tag)
    queryset = TaggedItem.objects.get_by_model(queryset_or_model, tag_instance)
    if not kwargs.has_key('extra_context'):
        kwargs['extra_context'] = {}
    kwargs['extra_context']['tag'] = tag_instance
    if related_tags:
        kwargs['extra_context']['related_tags'] = \
            Tag.objects.related_for_model(tag_instance, queryset_or_model,
                                          counts=related_tag_counts)
    return object_list(request, queryset, **kwargs)
Exemple #10
0
def how_V(s):
    wt = utils.get_tag(s)
    vlist = [w for w, t in wt if w.lower() not in stops and t.startswith('V')]
    if len(vlist) == 0:
        return ['is']
    return vlist
Exemple #11
0
def how(s1, s2):
    """
    s1 ='How do you imagine future?'
    s2 ='How can I imagine future?'
    
    utils.get_tag('How can you improve your intelligence ? ')
    utils.get_tag('How will I contact a genuine hacker ? ')
    utils.get_tag('How do you connect to wifi using TAILs ? ')
    
    """
    ret = ''
    # double how
    if s1.startswith('How') and s2.startswith('How'):
        ret += 'dh'

        rem = [' a ', ' an ', '?', ' the ', ' my ', ' your ']
        s1_rem = s1
        s2_rem = s2
        s1_ = s1.split()
        s2_ = s2.split()
        for r in rem:
            s1_rem = s1_rem.replace(r, ' ')
            s2_rem = s2_rem.replace(r, ' ')

        if s1 == s2:
            return ret + 'p1'

        elif s1_rem == s2_rem:
            return ret + 'p2'

        elif len(s1.split()) < 4 or len(s2.split()) < 4:
            return ret + 's'

        s1_wt = utils.get_tag(s1)
        s2_wt = utils.get_tag(s2)

        # How [do | can | will] [you | I | we] [verb] ~ ?
        if s1_wt[1][1] in ['VBP','VB','MD'] and s2_wt[1][1] in ['VBP','VB','MD'] and\
        s1_wt[3][1] == s2_wt[3][1] == 'VB' and\
        s1_wt[2][1] == s2_wt[2][1] == 'PRP' and len(s1_)>4 and len(s2_)>4:
            ret += '-vsv'

            # head 4 words match!!!
            if s1_[:4] == s2_[:4]:
                ret += '-h4'
                s1_wt = utils.get_tag(s1)
                s2_wt = utils.get_tag(s2)

                if len(s1_) == len(s2_) == 6:
                    ret += '-l6'
                    n1 = s1_[4]
                    n2 = s2_[4]
                    if pt(n1) == pt(n2):
                        return ret + '-a'
                    elif pt(n1.lower()) == pt(n2.lower()):
                        return ret + '-b'
                    else:
                        return ret + '-N'

                return find_nouns(s1_wt, s2_wt, ret)

            # head 3 words match!!!
            elif s1_[:3] == s2_[:3]:
                ret += '-h3'
                return ret

            # head 2 and 4- match
            elif s1_[1] == s2_[1] and s1_[3:] == s2_[3:]:
                """
                s1_ = 'How do I improve intelligence ?'.split()
                s2_ = 'How do you improve intelligence ?'.split()
                """
                ret += '-h2&4'

                return find_nouns(s1_wt, s2_wt, ret)

            # head 2 and 4- match
            elif s1_rem[1] == s2_rem[1] and s1_rem[3:] == s2_rem[3:]:
                """
                s1_ = 'How do I improve intelligence ?'.split()
                s2_ = 'How do you improve intelligence ?'.split()
                """
                ret += '-h2&4rem'
                return find_nouns(s1_wt, s2_wt, ret)

            # head 2 words match!!!
            elif s1_[:2] == s2_[:2]:
                ret += '-h2'
                return ret

            elif s1_[2:] == s2_[2:]:
                """
                s1_ = 'How can you improve intelligence ?'.split()
                s2_ = 'How do you improve intelligence ?'.split()
                """
                ret += '-2'
                return find_nouns(s1_wt, s2_wt, ret)

            elif s1_[3:] == s2_[3:]:
                """
                s1_ = 'How can I improve intelligence ?'.split()
                s2_ = 'How do you improve intelligence ?'.split()
                """
                ret += '-23'
                return find_nouns(s1_wt, s2_wt, ret)

            elif s1_[2:4] == s2_[2:4]:
                """
                s1_ = 'How should I prepare for the GATE CE ?'.split()
                s2_ = 'How do I prepare for the GATE CE 2018 ?'.split()
                """
                ret += '-1'

                return find_nouns(s1_wt, s2_wt, ret)


#            elif ret :
#                return ret
#
#            elif ret :
#                return ret
#
#            elif ret :
#                return ret
#
#            elif ret :
#                return ret
#
#            elif ret :
#                return ret

            else:
                return ret + '-N'

        else:
            ret += '-nvsv'
            return ret

        return ret  # dh

    else:
        return ret
    return ret