Skip to content

Commit

Permalink
Bad detect is word in dictionary
Browse files Browse the repository at this point in the history
Fixed a bug when "nie występuje w słowniku" was in comment section.
In this case to regex is input from <h1 tag , to KOMENTARZE: .
It means: from tag where is name of word to commentary section
  • Loading branch information
Damian Panasiuk committed Feb 26, 2021
1 parent 26f271c commit 3a3c646
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 20 deletions.
Binary file modified library/SjpApi.jar
Binary file not shown.
6 changes: 1 addition & 5 deletions src/CurlHelper.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package com.sjp.sjpapi;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class CurlHelper {

Expand All @@ -20,7 +16,7 @@ public static String getOutputFromCurl(String word) throws IOException {
String outputFromCurl = readCurlFromSJP(word);

if (validator.isCurlValidate(outputFromCurl) == true) {
return wrapper.deleteHeadFromOutput(outputFromCurl);
return wrapper.getBettwenH1AndCommentSection(outputFromCurl);
}
return "";
}
Expand Down
14 changes: 7 additions & 7 deletions src/CurlWrapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
public class CurlWrapper {

public String wrappCurl(String curlOutput) {
return deleteHeadFromOutput(curlOutput);
return getBettwenH1AndCommentSection(curlOutput);
}

public String deleteHeadFromOutput(String curlOutput) {
public String getBettwenH1AndCommentSection(String curlOutput) {

String outputWithoutHeadSection = curlOutput;
String outputBettwenH1AndComment = curlOutput;

String bodySectionStart = "<body>";
String bodySectionFinis = "</body>";
outputWithoutHeadSection = StringUtils.substringBettwen(outputWithoutHeadSection,bodySectionStart,bodySectionFinis);
String h1SectionStart = "<h1";
String CommentSectionStart = "KOMENTARZE:";
outputBettwenH1AndComment = StringUtils.substringBettwen(outputBettwenH1AndComment,h1SectionStart,CommentSectionStart);

return outputWithoutHeadSection;
return outputBettwenH1AndComment;
}


Expand Down
5 changes: 3 additions & 2 deletions src/StringUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,9 @@ public static final String unescapeHTML(String source, int start) {

public static final String substringBettwen(String substringString, String openingSequence, String closingSequence) {

int startSection = substringString.indexOf(openingSequence) + openingSequence.length();
int finisSection = substringString.indexOf("</body>");
//int startSection = substringString.indexOf(openingSequence) + openingSequence.length();
int startSection = substringString.indexOf(openingSequence);
int finisSection = substringString.indexOf(closingSequence);
substringString = substringString.substring(startSection, finisSection);

return substringString;
Expand Down
10 changes: 4 additions & 6 deletions test/CurlWrapperTest.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
package sjpAPI;
package com.sjp;

import junit.framework.TestCase;

import org.junit.Assert;

public class CurlWrapperTest extends TestCase {

private CurlWrapper wrapper = new CurlWrapper();

public void testIsNOTHeadInOutput() {
String mockCurl = "<head>asdasdsadasd</head> <body>fgdfggfhtyjfhghfgd</body> asfdfhtyhhjdffsdc";
public void testIsBettwenH1AndCommentSection() {
String mockCurl = "<head>asdasdsadasd</head> <body><h1>fgdfggfhtyjfhghfgd</h1>KOMENTARZE:</body> asfdfhtyhhjdffsdc";
mockCurl = wrapper.wrappCurl(mockCurl);
assertEquals(mockCurl,"fgdfggfhtyjfhghfgd");
assertEquals(mockCurl,"<h1>fgdfggfhtyjfhghfgd</h1>");

}
}

0 comments on commit 3a3c646

Please sign in to comment.