-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathObjectCleaner.java
More file actions
77 lines (67 loc) · 1.45 KB
/
ObjectCleaner.java
File metadata and controls
77 lines (67 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
class ObjectCleaner
{
private int textNumWordsPerLine;
ObjectCleaner()
{
this.textNumWordsPerLine = 5;
}
ObjectCleaner(int textNumWordsPerLine)
{
this.textNumWordsPerLine = textNumWordsPerLine;
}
private String replace( String s, String f, String r )
{
if (s == null) return s;
if (f == null) return s;
if (r == null) r = "";
int index01 = s.indexOf( f );
while (index01 != -1)
{
s = s.substring(0,index01) + r + s.substring(index01+f.length());
index01 += r.length();
index01 = s.indexOf( f, index01 );
}
return s;
}
public String cleanTextObject(String txt)
{
txt = replace(txt,"\n", "");
String [] words = txt.split(" ");
String result = "";
int wordCount = 0;
int lines = (words.length/this.textNumWordsPerLine)+1;
for(int word=0; word<words.length; word++)
{
if (words[word].matches("http.*"))
{
words[word] = "[URL]";
}
}
for(int i=0; i<lines; i++)
{
for(int j=0; j<this.textNumWordsPerLine; j++)
{
if(wordCount < words.length)
{
if(wordCount == words.length-1)
{
result += words[wordCount];
}else
{
result += words[wordCount] + " ";
}
wordCount ++;
}
else
{
break;
}
}
if(i!=lines-1)
{
result += "\n";
}
}
return result;
}
}