Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Checking grammar in documents is important to ensure clarity, professionalism, and accuracy. Well-written documents leave a positive impression and avoid misunderstandings. Grammar checks help identify and correct errors quickly, saving time and improving quality.
Aspose.Words allows users to check grammar and detect errors in documents using the OpenAI, Google, and Claude models' families listed in the AiModelType enumeration. Use the CheckGrammar method to analyze the text in a document and highlights grammatical problems.
The following code example shows how to use the GPT-4o mini model in Aspose.Words to check grammar:
Document doc = new Document("Big document.docx");
String apiKey = System.getenv("API_KEY");
// Use OpenAI generative language models.
IAiModelText model = (OpenAiModel)AiModel.create(AiModelType.GPT_4_O_MINI).withApiKey(apiKey);
CheckGrammarOptions grammarOptions = new CheckGrammarOptions();
grammarOptions.setImproveStylistics(true);
Document proofedDoc = model.checkGrammar(doc, grammarOptions);
proofedDoc.save("AI.AiGrammar.docx");Q: Which AI models can I use for grammar checking with Aspose.Words for Java?
A: The AiModelType enumeration lists all supported families, including OpenAI (e.g., GPT_4_O_MINI, GPT_4_TURBO), Google (e.g., GEMINI_PRO), and Anthropic Claude models. Choose the model that fits your accuracy and cost requirements.
Q: How do I provide the API key for the selected AI model?
A: Create the model instance with AiModel.create(...).withApiKey(yourKey). The key can be read from an environment variable, configuration file, or any secure store. Example:
String apiKey = System.getenv("API_KEY");
IAiModelText model = (OpenAiModel)AiModel.create(AiModelType.GPT_4_O_MINI).withApiKey(apiKey);
Q: Can I run checkGrammar on a document that is loaded from a stream instead of a file path?
A: Yes. Load the document from any InputStream using new Document(inputStream), then pass the Document object to model.checkGrammar. The API works the same regardless of how the document was created.
Q: Does the checkGrammar method modify the original Document instance?
A: No. checkGrammar returns a new Document containing the proofed content, leaving the original document unchanged. Save the returned document to persist the corrections.
Q: What licensing is required to use the AI grammar‑checking feature?
A: You need a valid Aspose.Words for Java license for the core library and a separate subscription or API key for the chosen AI service (OpenAI, Google, or Claude). The AI models are billed by the provider, not by Aspose. Ensure both licenses are active before invoking checkGrammar.
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.