如何创建一个对象,将词汇中单词的映射存储到其索引中?(How to create an object which stores mappings from a word in a vocabulary to its index?)
我在词汇表中有一个标记化的单词列表。 (它已经通过了一套,所以没有重复。)
我的问题
我想要生成一个方法来创建一个允许从词汇到词汇索引的映射的词典。
我的尝试
我目前的方法是这样的:
mapping = { w : vocabulary.index(w) for w in vocabulary }
这应该可行,但效率太低,可能是因为反复使用vocabulary.index(w)数千字。
题
有没有我可以使用的库,可以更高效地执行此操作? 或者只是更有效的方法?
谢谢。
可能的解决方案1
目前,每次在'词汇表'中达到一个单词时,词汇表将被实现,这需要通过'词汇表'来识别索引,这是针对每个单词完成的。 正如答案中所建议的那样,可能首先列举'词汇'。 这允许通过它来识别索引,如下所示:
mapping = { w : i for i, w in enumerate(vocabulary) }
I have a tokenized list of words in a vocabulary. (It's been passed through a set, so there are no duplicates.)
My problem
I want to generate a method which creates a dictionary that allows a mapping from the word to its index in the vocabulary.
My attempt
My current method is like so:
mapping = { w : vocabulary.index(w) for w in vocabulary }
This should work but it is far too inefficient, probably due to repeatedly using vocabulary.index(w) for thousands of words.
Question
Is there a library that I can use that does this more efficiently? Or just more efficient methods?
Thanks.
POSSIBLE SOLUTION 1
Currently, each time a word is reached in 'vocabulary', vocabulary.index() is implemented, which required a pass through 'vocabulary' to identify the index, which is done for every word. As suggested in an answer, a possibility is to enumerate 'vocabulary' first. This allows one pass through it to identify the index, like so:
mapping = { w : i for i, w in enumerate(vocabulary) }
原文:https://stackoverflow.com/questions/48842567
最满意答案
对于A部分,我使用了:
svn update --accept mine-full --force
对于B部分,我刚刚做了:
步骤1:
svn revert $localPath
第2步:
svn update $localPath
第3步(使用powershell + svn状态,但可以使用* nix中的rm -rf grep / sed完成):
svn status $localPath --no-ignore | Select-String '^[?I]' | ForEach-Object { [Regex]::Match($_.Line, '^[^\s]*\s+(.*)$').Groups[1].Value } | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
For Part A, I used:
svn update --accept mine-full --force
For Part B, I just did:
Step 1:
svn revert $localPath
Step 2:
svn update $localPath
Step 3 (using powershell + svn status, but can be done with rm -rf grep/sed in *nix):
svn status $localPath --no-ignore | Select-String '^[?I]' | ForEach-Object { [Regex]::Match($_.Line, '^[^\s]*\s+(.*)$').Groups[1].Value } | Remove-Item -Recurse -Force -ErrorAction SilentlyContinue
相关问答
更多-
git log --diff-filter=D --summary 请参阅在Git存储库中查找并还原已删除的文件 如果您不想要将所有有关哪些提交信息删除的信息,您可以在其中添加一个grep delete 。 git log --diff-filter=D --summary | grep delete git log --diff-filter=D --summary See Find and restore a deleted file in a Git repository If you don' ...
-
最简单的方法是使用: svn update --set-depth exclude
这将删除 从您的工作副本,但将其保留在存储库中。 请参阅稀疏目录的文档。 The easiest way to do is to use: svn update --set-depth exclude This will remove from your working copy, but leave it in the repository. See documentation on Sparse ... -
我只是试过了,它的工作完美。 $ svn st | grep '^!' | awk '{print $2}' | xargs svn delete --force D groups.pl D textblock.pl 您的文件在其名称中是否有空格? 等一下!! 我看到这个问题。 你有: svn --force delete 并不是: svn delete --force --force是delete命令的参数,而不是svn命令。 I just tried this an ...
-
在SVN存储库中删除的文件(Files deleted on SVN repository)[2023-04-15]
是的,除非用户对删除的项目具有“禁止访问”权限,否则它们将在工作副本中删除。 Yes, they will be removed in the working copies unless the users have No Access permissions on the removed items. -
从本地沙箱中删除文件对服务器没有影响。 每当您进行另一次update ,您都会收到这些文件。 如果要删除文件,请使用svn delete然后使用commit 。 即使这样,文件也不会从服务器中真正删除,如有必要,您仍然可以恢复它们。 使用TortoiseSVN在资源管理器中使用Context Menu, Tortoise SVN > Delete 。 要将新文件添加到存储库,请使用svn add然后使用commit 。 Deleting files from your local sandbox has n ...
-
对于A部分,我使用了: svn update --accept mine-full --force 对于B部分,我刚刚做了: 步骤1: svn revert $localPath 第2步: svn update $localPath 第3步(使用powershell + svn状态,但可以使用* nix中的rm -rf grep / sed完成): svn status $localPath --no-ignore | Select-String '^[?I]' | ...
-
从远程更新本地存储库,使用大写字母删除文件(假设您希望使用远程存储库中的小写字母保留文件),从工作树和索引中删除文件,将其提交并推送到远程,如下所示: git pull origin
--rebase rm //skip if file does not exist in local git rm -f git commit -m "Deleted Upper Case File" git push ... -
GIT删除了我的本地文件(GIT deleted my local files)[2022-05-17]
您提交了一些更改,然后通过发出“git merge filling-in-layout”获得了旧版本并恢复了它。 (你创建了一个分支“填充布局”) 无论你做什么都不要 - > git reset --hard < - 不要。 “git branch”说什么? 做这个: git checkout master (or one of the others) 看看哪一个是你的。 ;) You committed some changes, then got the old version and reverte ... -
最干净的解决方案如下: git rm --cached在本地git rm --cached了额外的文件(注意--cached选项将这些文件保存在工作目录中), 将它们添加到.gitignore文件中并在之后git commit -A -m "..." 推送您的分支(没有重写历史记录,但以前的历史记录将保留对这些文件的引用)。 如果您认为没有太多人从您的远程仓库(理想情况下,没有)撤出,您可以: 在本地修复您的提交历史 ( git rebase --interactive first-commit-with- ...
-
如果尚未提交删除,则下面的命令将恢复工作树中的已删除文件。 $ git checkout --
您可以使用以下命令获取工作树中所有已删除文件的列表。 $ git ls-files --deleted 如果已提交删除,请查找发生的提交,然后从此提交中恢复该文件。 $ git rev-list -n 1 HEAD -- $ git checkout ^ -- 如果您要查找要恢复的文件的路径,以下命令将显示所有已删除文件的摘要。 $ git log ...