使用 Aspose.Words for Java 搭配 OpenAI、Google 與 Claude AI 模型,偵測並標示文件中的文法錯誤。CheckGrammar 方法會分析 DOC、DOCX、RTF、PDF、HTML、Markdown、ODT、TXT 與 EPUB 檔案,並標記文法問題 — 協助您無需手動校對即可產出完美且專業的內容。
驗證需要您所選擇之 AI 提供者的 API 金鑰。如需支援模型的完整清單,請參閱 API 參考資料。
立即開始檢查 Java 中的文法 — 試用上方的即時示範。
// Repository path: https://releases.aspose.com/java/repo/
// Maven, where 'ver' - Aspose.Words version number, for example, 24.4.
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-words</artifactId>
<version>ver</version>
<classifier>jdk17</classifier>
</dependency>
複製
// Repository path: https://releases.aspose.com/java/repo/
// Gradle, where 'ver' - Aspose.Words version number, for example, 24.4.
compile(group: 'com.aspose', name: 'aspose-words', version: 'ver', classifier: 'jdk17')
複製
// Repository path: https://releases.aspose.com/java/repo/
// Ivy, where 'ver' - Aspose.Words version number, for example, 24.4.
<dependency org="com.aspose" name="aspose-words" rev="ver">
<artifact name="aspose-words" m:classifier="jdk17" ext="jar"/>
</dependency>
複製
// Repository path: https://releases.aspose.com/java/repo/
// Sbt, where 'ver' - Aspose.Words version number, for example, 24.4.
libraryDependencies += "com.aspose" % "aspose-words" % "ver"
複製
Document doc = new Document("Document.docx");
String apiKey = System.getenv("API_KEY");
// 使用 OpenAI 的生成式語言模型。
AiModel model = AiModel.create(AiModelType.GPT_4_O_MINI).withApiKey(apiKey);
CheckGrammarOptions grammarOptions = new CheckGrammarOptions();
grammarOptions.setImproveStylistics(true);
Document proofedDoc = model.checkGrammar(doc, grammarOptions);
proofedDoc.save("Output.docx")
Document doc = new Document("Document.docx");
// Pass an empty string if the self-hosted model does not require an API key.
AiModel model = new CustomAiModel().withApiKey("");
CheckGrammarOptions grammarOptions = new CheckGrammarOptions();
grammarOptions.setImproveStylistics(true);
Document proofedDoc = model.checkGrammar(doc, grammarOptions);
proofedDoc.save("Output.docx")
static class CustomAiModel extends OpenAiModel
{
protected String getUrl() { return "https://your-server.com/v1"; }
protected String getName() { return "my-model-24b"; }
}
我們在Maven存儲庫中託管我們的 Java 'Aspose.Words for Java' 是一個常見的包含字節碼的 JAR 請按照有關如何將其安裝到 Java 開發人員環境的分步說明進行操作。
Java SE 7 和更新的 Java 版本。 Java SE 6 提供了一個單獨的包,以防您不得不使用這個過時的 JRE 。
我們的 Java 包是跨平台的,可以在所有具有 JVM 實現的 Microsoft Windows 、Linux、macOS、Android 和 iOS。
有關可選包依賴項的信息,例如 JogAmp JOGL 、 Harfbuzz 字體引擎、 Java Advanced Imaging JAI ,請參閱產品文檔。