首页 \ 问答 \ jQuery自动完成标记插件,无需重复检查(jQuery autocomplete tagging plug-in without duplicate check)

jQuery自动完成标记插件,无需重复检查(jQuery autocomplete tagging plug-in without duplicate check)

我正在寻找一个没有重复检查的jQuery自动完成标记插件。 所以你可以多次选择一个项目。 我喜欢Select2插件,但有人知道如何禁用Select2中的重复ID检查功能。 创建者在4.0.0版本中提到了该功能,但我无法找到如何禁用它。 这里提到


I am looking for a jQuery autocomplete tagging plug-in without duplicate check. So you can select an item multiple times. I like Select2 plug in, but does anyone know how to disable the duplicate id check function in Select2. The creator mentioned that function in the 4.0.0 version but I could not find out how to disable that. It is mentioned here


原文:https://stackoverflow.com/questions/33606235
更新时间:2023-07-30 22:07

最满意答案

我不能在一行中作为正则表达式,但这是我尝试使用itertools和任何:

import pandas as pd
from itertools import product

url = pd.DataFrame({'urls' : ['www.amazon.com/ANASTASIA-Beverly...Brow/dp/B00GI21NZA', 'www.ulta.com/beautyservices/benefitbrowbar/']})
string_list = ['Benefit Cosmetics', 'Anastasia Beverly Hills']

"""
For each of Cartesian product (the different combinations) of 
string_list and urls.
"""
for x in list(product(string_list, url['urls'])):
    """
    If any of the words in the string (x[0]) are present in 
    the URL (x[1]) disregarding case.
    """
    if any (word.lower() in x[1].lower() for word in x[0].split()):
        """
        Show the match.
        """
        print ("Match String: %s URL: %s" % (x[0], x[1])) 

输出:

Match String: Benefit Cosmetics URL: www.ulta.com/beautyservices/benefitbrowbar/
Match String: Anastasia Beverly Hills URL: www.amazon.com/ANASTASIA-Beverly...Brow/dp/B00GI21NZA

更新:

您可以选择使用以下方式:

import pandas as pd
import warnings
pd.set_option('display.width', 100)
"""
Supress the warning it will give on a match.
"""
warnings.filterwarnings("ignore", 'This pattern has match groups')
string_list = ['Benefit Cosmetics', 'Anastasia Beverly Hills']
"""
Create a pandas DataFrame.
"""
url = pd.DataFrame({'urls' : ['www.amazon.com/ANASTASIA-Beverly...Brow/dp/B00GI21NZA', 'www.ulta.com/beautyservices/benefitbrowbar/']})
"""
Using one string at a time.
"""
for string in string_list:
    """
    Get the individual words in the string and concatenate them 
    using a pipe to create a regex pattern. 
    """
    s = "|".join(string.split())
    """
    Update the DataFrame with True or False where the regex 
    matches the URL.
    """
    url[string] = url['urls'].str.contains('('+s+')', case = False)
"""
Show the result
"""
print (url)

哪个会输出:

                                                urls Benefit Cosmetics Anastasia Beverly Hills
0  www.amazon.com/ANASTASIA-Beverly...Brow/dp/B00...             False                    True
1        www.ulta.com/beautyservices/benefitbrowbar/              True                   False

我想,如果你想在DataFrame中使用它,可能会更好,但我更喜欢第一种方式。


I can't do it as a regex in one line but here is my attempt using itertools and any:

import pandas as pd
from itertools import product

url = pd.DataFrame({'urls' : ['www.amazon.com/ANASTASIA-Beverly...Brow/dp/B00GI21NZA', 'www.ulta.com/beautyservices/benefitbrowbar/']})
string_list = ['Benefit Cosmetics', 'Anastasia Beverly Hills']

"""
For each of Cartesian product (the different combinations) of 
string_list and urls.
"""
for x in list(product(string_list, url['urls'])):
    """
    If any of the words in the string (x[0]) are present in 
    the URL (x[1]) disregarding case.
    """
    if any (word.lower() in x[1].lower() for word in x[0].split()):
        """
        Show the match.
        """
        print ("Match String: %s URL: %s" % (x[0], x[1])) 

Outputs:

Match String: Benefit Cosmetics URL: www.ulta.com/beautyservices/benefitbrowbar/
Match String: Anastasia Beverly Hills URL: www.amazon.com/ANASTASIA-Beverly...Brow/dp/B00GI21NZA

Updated:

The way you were looking at it you could alternatively use:

import pandas as pd
import warnings
pd.set_option('display.width', 100)
"""
Supress the warning it will give on a match.
"""
warnings.filterwarnings("ignore", 'This pattern has match groups')
string_list = ['Benefit Cosmetics', 'Anastasia Beverly Hills']
"""
Create a pandas DataFrame.
"""
url = pd.DataFrame({'urls' : ['www.amazon.com/ANASTASIA-Beverly...Brow/dp/B00GI21NZA', 'www.ulta.com/beautyservices/benefitbrowbar/']})
"""
Using one string at a time.
"""
for string in string_list:
    """
    Get the individual words in the string and concatenate them 
    using a pipe to create a regex pattern. 
    """
    s = "|".join(string.split())
    """
    Update the DataFrame with True or False where the regex 
    matches the URL.
    """
    url[string] = url['urls'].str.contains('('+s+')', case = False)
"""
Show the result
"""
print (url)

which would output:

                                                urls Benefit Cosmetics Anastasia Beverly Hills
0  www.amazon.com/ANASTASIA-Beverly...Brow/dp/B00...             False                    True
1        www.ulta.com/beautyservices/benefitbrowbar/              True                   False

Which I guess, if you want it in a DataFrame, may be better but I prefer the first way.

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)