A little while ago 一种lasdair Rae asked if any one had combined an anagram engine with a list of place names.

好吧,没有人上前,所以我认为这可能是一个有趣的项目。 而且,事实证明,尽管我不仅要考虑数据结构,而且要考虑地理位置,这还是很有趣的,但这对我来说可能是件好事。

我假设Alasdair可能不仅仅对字母的排列感兴趣,而是想要实际的单词(例如在填字游戏线索中使用的单词)。 我也将搜索范围限制在单个单词字谜上,因为看不到找到多个单词解决方案的简单解决方案。

首先,我将军械测量开放名称数据集填充到PostGIS中(就像谁想要扫描数百个小的csv文件一样)。

I then set up a GeoTool’s PostG一世S datastore and grabbed the populated places.

Map<String, Object> params = new HashMap<String, Object>();params.put(PostgisNGDataStoreFactory.DBTYPE.key, PostgisNGDataStoreFactory.DBTYPE.sample);params.put(PostgisNGDataStoreFactory.USER.key, "username");params.put(PostgisNGDataStoreFactory.PASSWD.key, "password");params.put(PostgisNGDataStoreFactory.SCHEMA.key, "opennames");params.put(PostgisNGDataStoreFactory.DATABASE.key, "osdata");params.put(PostgisNGDataStoreFactory.HOST.key, "127.0.0.1");params.put(PostgisNGDataStoreFactory.PORT.key, "5432");DataStore ds = DataStoreFinder.getDataStore(params);if (ds == null) {throw new RuntimeException("No datastore");}SimpleFeatureSource fs = ds.getFeatureSource("opennames");SimpleFeatureCollection features = fs.getFeatures(CQL.toFilter("type = 'populatedPlace'"));

我尝试了一种幼稚的方法,即从名称中递归地找到每个字谜,然后在一个HashMap of English words. Oddly, this took a long time so I thought (and Googled) some more and came up with the much more efficient way of sorting the letters in a word and using that as a key to all words that contained those letters. Then I could sort each place name’s letters and do a single lookup to find all the possible words that could be made with those letters. That speeded things up nicely.

To build the lookup table I made use of Google’s HashMultimap (fromGuava) which allows you to create a Map ofCollections keyed on a String.

private Map<String, Collection<String>> dict;public AnagramLookup() throws FileNotFoundException, IOException {//change this to point to your dictionary (one word per line)File f = new File("/usr/share/dict/british-english");HashMultimap<String, String> indexedDictionary = HashMultimap.create();try (BufferedReader buf = new BufferedReader(new FileReader(f))) {String line;// read each word in the dictionarywhile ((line = buf.readLine()) != null) {//strip out non lettersString word = line.toLowerCase().replaceAll("\\W", "");//store the word against the sorted keyindexedDictionary.put(sort(word), word);}}dict = indexedDictionary.asMap();}

然后,剩下要做的就是遍历每个人口稠密的地方,抓住它的名字,然后删除所有非字母并对其字母进行排序,然后在HashMap. The final trick is to remove the name itself if it appears in the list of anagrams (i.e. the name itself is an English word).

try (SimpleFeatureIterator itr = features.features()) {while (itr.hasNext()) {SimpleFeature f = itr.next();String name = (String) f.getAttribute("name1");current = name.toLowerCase().replaceAll("\\W", "");Collection<String> anagrams = getAnagrams(current);if(anagrams!=null && !anagrams.isEmpty()) {//remove the name itself if it happens to be a wordanagrams.remove(current);if(!anagrams.isEmpty()) {results.put(name, new TreeSet<String>(anagrams));}}}}

Results

事实证明,GB地名列表有6个11个字母的字谜。

  • Balnadelson - belladonnas
  • Fortis Green - reforesting
  • Gilling East - legislating
  • Green Plains - spenglerian
  • Morningside - modernising
  • Sharrington - harringtons
  • Stone Corner - cornerstone

A Spenglerian is “of or relating to the theory of world history developed by Oswald Spengler which holds that all major cultures undergo similar cyclical developments from birth to maturity to decay”. While aHarrington is “a man’s short lightweight jacket with a collar and a zipped front.”

填字游戏二传手的其他亮点包括Aimes Green(管理人员)和Westlinton(金属丝镇)。

I have posted the full list of anagrams and the code to generate the list.

See this follow up for world names.

04-26.eri-test 查找地名的字谜(以GB为单位)相关推荐

  1. 查找地名的字谜(以GB为单位)

    A little while ago 一种lasdair Rae asked if any one had combined an anagram engine with a list of plac ...

  2. v1.0.2-2017.04.26

    v1.0.2-2017.04.26 增加支付宝.微信查询接口 增加订单轮询工程 增加网关下单后发起订单轮询业务流程 v1.0.1-2017.04.05 修复分页乱码bug 增加支付密码字段.商户服务器 ...

  3. English Learning - L3 综合练习 1 VOA-Color 2023.04.26 周三

    English Learning - L3 综合练习 1 VOA-Color 2023.04.26 周三 主题 整体听一遍 精听 句子 1 扩展 way of doing | way to do st ...

  4. (学习日记)2023.04.26

    写在前面: 由于时间的不足与学习的碎片化,写博客变得有些奢侈. 但是对于记录学习(忘了以后能快速复习)的渴望一天天变得强烈. 既然如此 不如以天为单位,以时间为顺序,仅仅将博客当做一个知识学习的目录, ...

  5. PC移植安卓---2018/04/26

    记录一下碰到的问题: 1.Assetbundle加载问题: 原PC打包后的AssetBundle导入安卓工程后,加载会出问题.同时工程打包APK时,StreamingAssets中不能有中文. 解决方 ...

  6. WORD 批量查找地名

    利用已有的关键字,检查文件夹下面所有WORD文档中是否包含关键字. 可用于招标文件.项目验收资料.投标文件等检查地名.敏感文字.文件关键字等. 操作过程: 1.打开 word文件检查.exe 2.设置 ...

  7. 18.04.26 魔兽世界终极版

    A:魔兽世界终极版 描述 魔兽世界的西面是红魔军的司令部,东面是蓝魔军的司令部.两个司令部之间是依次排列的若干城市,城市从西向东依次编号为1,2,3 .... N ( N <= 20 ).红魔军 ...

  8. 2007.04.26

    这个博客就记录自己的心情,虽然感觉写的东西灰暗了一点,消极了一点,但是作为自己发泄的一个途径把.很多话,再好的知心朋友也不能说,只能放在心里,每天写一点博客,让自己轻松一点.以后坚持每天睡觉前写一点, ...

  9. Cheatsheet: 2010 04.26 ~ 04.30

    Web Telling robots about your crawl-able Ajax apps Scrollin' Scrollin' Scrollin' to the NextPoint Th ...

最新文章

  1. 5教程 watchout_Unit 5单元复习学案设计
  2. JustForex开始提供比特币和比特币现金支付方式
  3. .NET混淆器 Dotfuscator使用教程七:加强保护之改进重命名混淆
  4. github设置仓库可见性 私人仓库设置
  5. MC缓存序列化php,PHP serialize()序列化的使用
  6. java 分页原理_关于javaweb分页原理
  7. 通过Gogs部署git仓库
  8. 华为鸿蒙系统学习笔记3-方舟编译器介绍
  9. the dhc driver package_DHC智商低?不,它用1k阅读,444个好看证明了自己
  10. HaLow技术提升车载Wi-Fi质量 促进车联网发展
  11. java输出两个整数的积_如何检查Java中的两个数字相乘是否会导致溢出?
  12. OpenGL加载纹理glGenTextures——内存优化(OpenGL内存泄漏)
  13. 完整的网络端口表《三》
  14. 统计图源代码_openlayers4 入门开发系列结合 echarts4 实现统计图(附源码下载)
  15. 【RBM】受限玻尔兹曼机(Restricted Boltzmann Machine, RBM) 简介
  16. sola病毒批量恢复工具 —— 大一的回忆
  17. linux mysql免安装版配置_Linux下MySQL免安装版安装配置记录
  18. ADS1115的IIC通信
  19. android 谷歌地图真实距离,Android谷歌地图点之间的距离
  20. 使用矩阵分解找到相似歌曲

热门文章

  1. 基于ARM Cortex M0国产32位单片机MM32SPIN220B
  2. 使用Java编写,写出1-100的偶数和奇数
  3. hook stringWithFormat
  4. vhdl文件添加c语言头文件,C语言对VHDL设计文件的协同仿真 - 基于Modelsim FLI接口的协同仿真技术...
  5. 中文字符频率统计python_用Python数据分析方法进行汉字声调频率统计分析
  6. scl enable devtoolset-7踩坑
  7. 单机秒杀系统的架构设计与实现
  8. 有序神经元LSTM:ON-LSTM
  9. FileSystemObject 的疑惑
  10. 浪漫情人节-情人节由来