Tag: 匹配

计算字符串匹配数

我想获得列表中最小的字符串匹配。 虽然我这样做是成功的,但问题是我想要计算出已经进行了多少次匹配计数: List mylist=new LinkedList(); Set result=new LinkedHashSet(); mylist.add(“interpreter”); mylist.add(“interprete”); mylist.add(“interpret”); mylist.add(“developed”); mylist.add(“develops”); mylist.add(“develop”); mylist.add(“interpret”); String small=””; Collections.sort(mylist); Collections.reverse(mylist); for(int i=0;i<mylist.size();i++) { small=mylist.get(i); for(int j=i;j<mylist.size();j++) { if(small.contains(mylist.get(j))) { small=mylist.get(j); } } result.add(small); } for (String string : result) { System.out.println(string); } 所以输出应该是: interpret=4 develop=4 我正在尝试以下代码出现问题: List mylist=new LinkedList(); Set result=new LinkedHashSet(); mylist.add(“interpreter”); mylist.add(“interprete”); mylist.add(“interpret”); mylist.add(“developed”); […]

用Java实现的最佳模式匹配算法

我是Java新手。 我的问题是我必须选择整个文件的行(大小小于70MB)来匹配我的模式(例如 )。 目前我使用基本的字符串匹配算法位需要时间,所以我想使用“Boyer-Moore算法”。 使用起来好吗? 我们还有其他更好的解决方案吗? 如果是,请告诉我,代码也是Java。

如何获取String中所有匹配的位置?

我有一个文本文档和一个查询(查询可能不止一个单词)。 我想在文档中找到所有出现的查询的位置。 我想到了documentText.indexOf(query)或使用正则表达式,但我无法使其工作。 我最终得到以下方法: 首先,我创建了一个名为QueryOccurrence的dataType public class QueryOccurrence implements Serializable{ public QueryOccurrence(){} private int start; private int end; public QueryOccurrence(int nameStart,int nameEnd,String nameText){ start=nameStart; end=nameEnd; } public int getStart(){ return start; } public int getEnd(){ return end; } public void SetStart(int i){ start=i; } public void SetEnd(int i){ end=i; } } 然后,我在以下方法中使用了此数据类型: public static ListFindQueryPositions(String […]

Javagenerics – 实现像map这样的高阶函数

我决定在Java中编写一些常见的高阶函数(map,filter,reduce等),这些函数通过generics是类型安全的,而且我遇到了在一个特定函数中匹配通配符的问题。 为了完整,函子接口是这样的: /** * The interface containing the method used to map a sequence into another. * @param The type of the elements in the source sequence. * @param The type of the elements in the destination sequence. */ public interface Transformation { /** * The method that will be used in map. * @param […]

使用括号replaceAll方法Java

我想在一个句子中改变一个单词,但这个单词有括号。 我把它保存在String变量中。 在变量st里面我有 manages(P0,MT0) 在其他String变量DES内部,我有以下句子: query(MT0, P0) :- not(manages(P0,MT0)), ins_manages(P0,MT0), not(physician(P0)), not(ins_physician(P0)) 所以我有另一个字符串变量querypart存储新单词: managesa 我在代码中尝试的是: EDC = EDC.replaceAll(st,querypart); 但它不起作用。 我认为问题可能是paranthesis,所以我像st变量一样更改了字符串: manages\\(P0,MT0\\) 然后我试了 EDC = EDC.replaceAll(st,querypart); 但我得到了一些结果。 问题是当我像这样使用replaceAll时: EDC = EDC.replaceAll(“manages\\(P0,MT0\\)”,querypart); 句子改变了 query(MT0, P0) :- not(managesa), ins_manages(P0,MT0), not(physician(P0)), not(ins_physician(P0)) 我想这是因为括号,但我找不到任何解决方案呢? 解决办法是什么?

Java中的字符串搜索算法

我正在使用大量数据进行字符串匹配。 编辑:我正在匹配一个大列表中的单词与一些本体文本文件。 我从本体中获取每个文件,并搜索每个文件行的第三个字符串与列表中的任何单词之间的匹配。 我在监督这样一个事实上犯了一个错误:我需要做的不是纯匹配(结果很差),但我需要一些更宽松的匹配函数,当字符串包含在另一个字符串中时,它也会返回结果。 我用Radix Trie做到了这一点; 这是非常快,工作得很好,但现在我猜我的工作没用,因为trie只返回完全匹配。 :/ 执行此操作的算法类型是字符串搜索算法? 有人可以建议一些他有经验的Java实现吗? 算法应该很快,但不是最重要的,会与速度和复杂性相提并论。 我非常感谢所有建议/示例/解释/链接! 谢谢!

匹配所有url,不包括jpg,gif,png

我想匹配所有url但排除与该正则表达式匹配的图像url:jpe?g | gif | png。 (?:HTTPS | FTP |文件):\ b // [?-A-Z0-9 + @#/%=〜_ | $!。;] * A-Z0-9 + @# /%=〜_ | $ 问题是带有排除的部分不是这样的:(?!jpe?g | gif | png) 有人有解决方案吗? 例: 不是马辰: http://example.com/example.jpg http://example.com/example231/example.gif 比赛: http://example.com/example.html http://example.com/example/?id=4331 http://example.com/example/example/ex_ample/ex-ample/?id=4331

Java中的字符串模式匹配

我想在输入sting中搜索给定的字符串模式。 对于Eg。 String URL = “https://localhost:8080/sbs/01.00/sip/dreamworks/v/01.00/cui/print/$fwVer/{$fwVer}/$lang/en/$model/{$model}/$region/us/$imageBg/{$imageBg}/$imageH/{$imageH}/$imageSz/{$imageSz}/$imageW/{$imageW}/movie/Kung_Fu_Panda_two/categories/3D_Pix/item/{item}/_back/2?$uniqueID={$uniqueID}” 现在我需要搜索字符串URL是否包含“ /{item}/ ”。 请帮帮我。 这是一个例子。 其实我需要检查URL是否包含匹配“/ {a-zA-Z0-9} /”的字符串