Skip to content

Commit dd8ebf3

Browse files
author
Changjian Wang
committed
Update sample file paths and add new sample documents for content understanding SDK
1 parent fedf711 commit dd8ebf3

File tree

6 files changed

+8
-27
lines changed

6 files changed

+8
-27
lines changed

sdk/contentunderstanding/azure-ai-contentunderstanding/src/samples/java/com/azure/ai/contentunderstanding/samples/Sample01_AnalyzeBinary.java

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,26 +52,10 @@ public static void main(String[] args) throws IOException {
5252
// END: com.azure.ai.contentunderstanding.sample01.buildClient
5353

5454
// Load the sample file
55-
String filePath = "src/test/resources/sample_invoice.pdf";
55+
String filePath = "src/samples/resources/sample_invoice.pdf";
5656
Path path = Paths.get(filePath);
57-
58-
byte[] fileBytes;
59-
BinaryData binaryData;
60-
boolean hasRealFile = Files.exists(path);
61-
62-
// Check if sample file exists
63-
if (!hasRealFile) {
64-
System.out.println("⚠️ Sample file not found at " + filePath);
65-
System.out.println("Creating a minimal test PDF for demonstration...");
66-
// Create a minimal valid PDF for testing
67-
String pdfContent
68-
= "%PDF-1.4\n1 0 obj<</Type/Catalog/Pages 2 0 R>>endobj 2 0 obj<</Type/Pages/Kids[3 0 R]/Count 1>>endobj 3 0 obj<</Type/Page/MediaBox[0 0 612 792]/Parent 2 0 R/Resources<<>>>>endobj\nxref\n0 4\n0000000000 65535 f\n0000000009 00000 n\n0000000056 00000 n\n0000000115 00000 n\ntrailer<</Size 4/Root 1 0 R>>\nstartxref\n203\n%%EOF";
69-
fileBytes = pdfContent.getBytes();
70-
} else {
71-
fileBytes = Files.readAllBytes(path);
72-
}
73-
74-
binaryData = BinaryData.fromBytes(fileBytes);
57+
byte[] fileBytes = Files.readAllBytes(path);
58+
BinaryData binaryData = BinaryData.fromBytes(fileBytes);
7559

7660
// BEGIN:ContentUnderstandingAnalyzeBinaryAsync
7761
SyncPoller<ContentAnalyzerAnalyzeOperationStatus, AnalyzeResult> operation
@@ -99,12 +83,9 @@ public static void main(String[] args) throws IOException {
9983
}
10084
// END:ContentUnderstandingExtractMarkdown
10185

102-
if (hasRealFile && content != null && content.getMarkdown() != null && !content.getMarkdown().isEmpty()) {
86+
if (content != null && content.getMarkdown() != null && !content.getMarkdown().isEmpty()) {
10387
System.out
10488
.println("Markdown content extracted successfully (" + content.getMarkdown().length() + " characters)");
105-
} else {
106-
System.out
107-
.println("⚠️ Skipping markdown content validation (using minimal test PDF or no markdown available)");
10889
}
10990

11091
// BEGIN:ContentUnderstandingAccessDocumentProperties

sdk/contentunderstanding/azure-ai-contentunderstanding/src/samples/java/com/azure/ai/contentunderstanding/samples/Sample10_AnalyzeConfigs.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ public static void main(String[] args) throws IOException {
5757
System.out.println("Client initialized successfully");
5858

5959
// BEGIN:ContentUnderstandingAnalyzeWithConfigs
60-
// Load local test file
61-
Path filePath = Paths.get("src/test/resources/sample_document_features.pdf");
60+
// Load local sample file
61+
Path filePath = Paths.get("src/samples/resources/sample_document_features.pdf");
6262
byte[] fileBytes = Files.readAllBytes(filePath);
6363

6464
com.azure.ai.contentunderstanding.models.AnalyzeInput input

sdk/contentunderstanding/azure-ai-contentunderstanding/src/samples/java/com/azure/ai/contentunderstanding/samples/Sample11_AnalyzeReturnRawJson.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ public static void main(String[] args) throws IOException {
5555
System.out.println("Client initialized successfully");
5656

5757
// BEGIN:ContentUnderstandingAnalyzeReturnRawJson
58-
// Load local test file
59-
Path filePath = Paths.get("src/test/resources/sample_invoice.pdf");
58+
// Load local sample file
59+
Path filePath = Paths.get("src/samples/resources/sample_invoice.pdf");
6060
byte[] fileBytes = Files.readAllBytes(filePath);
6161

6262
// Prepare request body with binary data using JSON format
Binary file not shown.

0 commit comments

Comments
 (0)