使用位置(索引)号来查找文本文件中的单词? java的 [英] using position (index) number to find words in text files? java

查看:213
本文介绍了使用位置(索引)号来查找文本文件中的单词? java的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有文本(段落),我想用段落中错误单词的位置(索引)编号指示的正确单词替换段落中的每个带注释的错误单词,我需要为每个段落执行... 那么,我应该用什么方法来搜索索引号?谢谢





例如:



在输入文件你有以下段落:



计算机科学是对原理应用,计算和技术的研究。电脑。它涉及数据和数据结构的研究......



上述文本应由输出文件中的以下段落替换:



计算机科学是对计算机和计算机的原理,应用和技术的研究。它涉及数据和数据结构的研究......



**注意数字(例如:2 3)表示错误单词的位置(索引)



A 2 3 |||编辑|||是|||必需||| -NONE- ||| 0



A 12 13 |||编辑|||和||| REQUIRED ||| -NONE- ||| 0



A 15 16 |||编辑|||涉及|||必需||| -NONE- ||| 0



A 18 19 |||拆分|||研究|||必需||| -NONE- ||| 0



A 29 29 ||| Add_before |||。||| REQUIRED ||| -NONE- ||| 0

I have texts (Paragraphs) and I want to replace each of annotated wrong word in the paragraph with the correct word indicated by the position (index) number of the wrong word and i need to do it for each paragraph... So, what method should I use to search by index number? thank you


Example:

In the input file you have the following paragraph:

Computer Science are the study of principles applications, and technologies of computing & computers. It involve the studyof data and data structures...

The above text should be replaced by the following paragraph in the output file:

Computer Science is the study of principles, applications, and technologies of computing and computers. It involves the study of data and data structures...

**Note that the numbers (e.g:2 3) indicate the position (index) of the wrong word

A 2 3|||Edit||| is |||REQUIRED|||-NONE-|||0

A 12 13|||Edit||| and |||REQUIRED|||-NONE-|||0

A 15 16|||Edit||| involves |||REQUIRED|||-NONE-|||0

A 18 19|||Split|||study of|||REQUIRED|||-NONE-|||0

A 29 29|||Add_before|||.|||REQUIRED|||-NONE-|||0

推荐答案

首先,您需要使用 StreamReader 类来读取文件。您还需要一些方法来确定每个段落结束的位置。完成后,您可以使用 String 类将段落拆分为单词数组。这将允许您按索引查找特定项目。您可能需要编写自己的拆分器方法以允许标点字符。然后,您可以从数组重建段落(在更改后),并将其写入新文件。请参阅 http://docs.oracle.com/javase/tutorial/essential/io/index.html [ ^ ]有关流I / O类的信息。
First you will need to use a StreamReader class to read the file. You will also need some way of identifiying where each paragraph ends. Once you have that then you can use the String class to split the paragraph into an array of words. That will allow you to find a specific item by index. You may need to code your own splitter method to allow for punctuation characters. You can then rebuild the paragraph from the array (after the change), and write it out to the new file. See http://docs.oracle.com/javase/tutorial/essential/io/index.html[^] for information on the stream I/O classes.


这篇关于使用位置(索引)号来查找文本文件中的单词? java的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆