目前,我正在努力为Minecraft开发一个自动聊天处理程序,在那里我可以使用某些字符串/单词,并查看它们与一组列入黑名单的单词的距离。目前,我找到了将字符串转换为图像的代码Convert text content to Image,但是,我需要找到如何创建识别单词的学习机制。因此,如果输入单词“tèst”,程序将识别为字符e,并将该字母替换为表单测试,这将取消该消息。目前,我的代码基于之前提供的链接如下:
import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
public class Scan {
public Scan () {}
public void scan (String text) {
BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_INT_ARGB);
Graphics2D g2d = img.createGraphics();
Font font = new Font("Arial", Font.PLAIN, 48);
g2d.setFont(font);
FontMetrics fm = g2d.getFontMetrics();
int width = fm.stringWidth(text);
int height = fm.getHeight();
g2d.dispose();
img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
g2d = img.createGraphics();
g2d.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2d.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_ENABLE);
g2d.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
g2d.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
g2d.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE);
g2d.setFont(font);
fm = g2d.getFontMetrics();
g2d.setColor(Color.BLACK);
g2d.drawString(text, 0, fm.getAscent());
g2d.dispose();
try {
ImageIO.write(img, "png", new File("TEMP_TEXT.png"));
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
理想情况下,我希望能有一些相对较快的东西,但即使它很慢,也应该好好学习。
答案 0 :(得分:1)
您应该实施一些机器学习来过滤它。我建议这样做:Google Tensorflow.
虽然机器学习可能需要陡峭的学习曲线,但您可以按照https://developers.google.com/machine-learning/crash-course/上的教程进行操作。