java 文本提取,从java中的文本文件中提取短语

i'm doing project on host based intrusion detection using ADFA-LD dataset ,now i'm doing feature extraction module. i constructed the phrase dictionary which consists of system call phrases of length 4. And now for feature extraction ,i need to compare the phrases with the new system call traces (following are some samples):

sys_clock_gettime sys_poll sys_poll sys_clock_gettime sys_poll sys_poll

sys_poll sys_clock_gettime sys_poll sys_clock_gettime sys_poll sys_poll sys_poll sys_poll sys_poll sys_poll sys_poll sys_poll sys_socketcall.......

What i need is, how can i compare these phrases with the new traces. i'm doing in java.

my phrase dictionary:

sys_socketcall-sys_poll-sys_clock_gettime-sys_poll

sys_clock_gettime-sys_poll-sys_poll-sys_socketcall

sys_poll-sys_socketcall-sys_poll-sys_clock_gettime

sys_poll-sys_clock_gettime-sys_clock_gettime-sys_clock_gettime

sys_clock_gettime-sys_clock_gettime-sys_socketcall-sys_clock_gettime

sys_socketcall-sys_clock_gettime-sys_poll-sys_poll

sys_poll-sys_poll

i'm using '-' as separator on comparing these phrases with the new traces, so i joined unique system calls with '-'.

解决方案

It seems like your desired words are divided by space. In that case just read your file line by line, and then get your words using String.split(" ").

Here is the one i might think of:

public class FileSplitter {

public static void main(String[] args) throws IOException {

File file = new File("input_file.txt");

LinkedList words = new LinkedList();

int i = 0;

Files.lines(file.toPath()).

forEachOrdered(line -> words.

addAll(Arrays.asList(line.split(" "))));

for(String word:words){

if(word.trim().length() > 0){

System.out.print(word.trim() + " ");

if(i++ >= 3){

System.out.println();

i = 0;

}

}

}

}

}

For your example it returns this:

sys_clock_gettime sys_poll sys_poll sys_clock_gettime

sys_poll sys_poll sys_poll sys_clock_gettime

sys_poll sys_clock_gettime sys_poll sys_poll

sys_poll sys_poll sys_poll sys_poll

sys_poll sys_poll sys_socketcall

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值