-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[FEAT] 욕설 필터링 업그레이드 #69
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
4fb801a
📦️ [CHORE] TODO 설정
dong2ast 6e9ec8a
🐛 [FIX] 레큐 북 Swagger example 수정
dong2ast b52d69e
✨ [FEAT] 욕설 어절단위로 필터링되게 변환
dong2ast cf6a26e
✨ [FEAT] 욕설 DB 생성
dong2ast d2a63c5
Merge branch 'develop' into feat/#68-upgrade_badword_filter
dong2ast bed6654
[CHORE] Swagger 색깔코드 변경
dong2ast 2a71061
Merge branch 'develop' into feat/#68-upgrade_badword_filter
dong2ast File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/org/sopt/lequuServer/domain/log/model/BadWordLog.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package org.sopt.lequuServer.domain.log.model; | ||
|
||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import org.sopt.lequuServer.global.common.model.BaseTimeEntity; | ||
|
||
@Entity | ||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "bad_word_log") | ||
public class BadWordLog extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "bad_word_log_id") | ||
private Long id; | ||
|
||
private Long memberId; | ||
|
||
private String originText; | ||
|
||
@Builder | ||
public BadWordLog(Long memberId, String originText) { | ||
this.memberId = memberId; | ||
this.originText = originText; | ||
} | ||
|
||
public static BadWordLog of(Long memberId, String originText) { | ||
return new BadWordLog(memberId, originText); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/org/sopt/lequuServer/domain/log/repository/BadWordLogRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.sopt.lequuServer.domain.log.repository; | ||
|
||
import org.sopt.lequuServer.domain.log.model.BadWordLog; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface BadWordLogRepository extends JpaRepository<BadWordLog, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
package org.sopt.lequuServer.global; | ||
|
||
import com.vane.badwordfiltering.BadWordFiltering; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.io.BufferedReader; | ||
import java.io.IOException; | ||
import java.io.InputStreamReader; | ||
import java.net.URL; | ||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import org.sopt.lequuServer.domain.log.model.BadWordLog; | ||
import org.sopt.lequuServer.domain.log.repository.BadWordLogRepository; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
|
||
@Service | ||
|
@@ -17,13 +21,14 @@ public class BadWordFilterService { | |
private final BadWordFiltering badWordFiltering; | ||
private final HashSet<String> badWords; | ||
private final String[] symbols; | ||
private final BadWordLogRepository badWordLogRepository; | ||
|
||
public BadWordFilterService() throws IOException { | ||
badWordFiltering = new BadWordFiltering(); | ||
public BadWordFilterService(BadWordLogRepository badWordLogRepository) throws IOException { | ||
badWordFiltering = new BadWordFiltering("♡"); | ||
symbols = new String[]{"!", "@", "#", "$", "%", "^", "&", "*", "_"}; | ||
|
||
// 비속어 필터링을 제외할 단어 설정 가능 | ||
String[] enableList = new String[]{"똥"}; | ||
String[] enableList = new String[]{"똥", "바보"}; | ||
for (String s : enableList) { | ||
badWordFiltering.remove(s); | ||
} | ||
|
@@ -33,10 +38,31 @@ public BadWordFilterService() throws IOException { | |
|
||
readBadWords("BadWord.txt"); | ||
badWordFiltering.addAll(badWords); | ||
|
||
this.badWordLogRepository = badWordLogRepository; | ||
} | ||
|
||
public String badWordChange(String string) { | ||
return badWordFiltering.change(string, symbols); | ||
@Transactional | ||
public String badWordChange(Long memberId, String string) { | ||
String changedWord = badWordFiltering.change(string, symbols); | ||
|
||
if (!changedWord.equals(string)) { | ||
badWordLogRepository.save(BadWordLog.of(memberId, string)); | ||
|
||
String[] split = changedWord.split(" "); | ||
List<String> result = new ArrayList<>(); | ||
|
||
for (String s : split) { | ||
if (s.contains("♡")){ | ||
result.add(s.replaceAll(".", "♡")); | ||
continue; | ||
} | ||
result.add(s); | ||
} | ||
return String.join(" ", result); | ||
} | ||
|
||
return changedWord; | ||
Comment on lines
+49
to
+65
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 와우 직접 바꿨네요 :) |
||
} | ||
|
||
private void readBadWords(String fileName) throws IOException { | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
하트로 잘 바꼈군요!ㅋㅎ