[ 
https://issues.apache.org/jira/browse/TIKA-4766?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18110772#comment-18110772
 ] 

ASF GitHub Bot commented on TIKA-4766:
--------------------------------------

Copilot commented on code in PR #2961:
URL: https://github.com/apache/tika/pull/2961#discussion_r3916770701


##########
tika-grpc-mapper/src/main/java/org/apache/tika/grpc/mapper/DocumentBuilder.java:
##########
@@ -0,0 +1,168 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.tika.grpc.mapper;
+
+import java.time.Instant;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.tika.Tika;
+import org.apache.tika.digest.DigestDef;
+import org.apache.tika.grpc.mapper.transform.DocumentTransformers;
+import org.apache.tika.grpc.v2.Document;
+import org.apache.tika.grpc.v2.ParseStatus;
+import org.apache.tika.grpc.v2.SourceOrigin;
+import org.apache.tika.metadata.HttpHeaders;
+import org.apache.tika.metadata.Metadata;
+import org.apache.tika.metadata.TikaCoreProperties;
+
+/**
+ * Builds a {@link Document} from Tika's parse output: the envelope (content 
type,
+ * origin, status), the typed Dublin Core metadata via {@link 
DocumentTransformers},
+ * and the lossless tagged tail for everything else.
+ */
+public final class DocumentBuilder {
+
+    private static final DocumentTransformers TRANSFORMERS = 
DocumentTransformers.defaults();
+
+    // The key the parse pipeline records the source digest under when a 
digester is
+    // configured. Derived from DigestDef so it cannot drift from the 
producer: a
+    // hand-rolled "...SHA256" copy of it did, silently, when the algorithm 
keys moved
+    // to their Java names ("SHA-256").
+    private static final String SHA256_DIGEST_KEY =
+            new DigestDef(DigestDef.Algorithm.SHA256, 
DigestDef.Encoding.HEX).metadataKey();
+
+    private DocumentBuilder() {
+    }
+
+    /**
+     * Maps Tika parse output to {@link Document}. Pass {@code primary == 
null} when the
+     * pipes result carried no metadata at all (e.g. a fetch failure, or a 
crash before
+     * the parse produced anything): the returned Document then has only an id 
and a
+     * status. The status still derives from {@code pipesStatus} 

> Replace tika-grpc fields map with a typed Document parse contract
> -----------------------------------------------------------------
>
>                 Key: TIKA-4766
>                 URL: https://issues.apache.org/jira/browse/TIKA-4766
>             Project: Tika
>          Issue Type: New Feature
>          Components: tika-pipes
>    Affects Versions: 4.0.0
>            Reporter: Kristian Rickert
>            Priority: Major
>              Labels: grpc, pipes, protobuf
>
> Replace the flat {{FetchAndParseReply.fields}} map ({{map<string,string>}}) 
> with a typed parse result.
> Approach (reshaped from the original {{ParseResponse}} design after review in 
> [PR #2916|https://github.com/apache/tika/pull/2916]): a single small 
> {{Document}} proto (~200 lines) rather than per-format metadata messages.
> * *Content*: a structured markdown block tree -- headings, paragraphs, lists, 
> tables, code blocks, inline runs (CommonMark + GFM) -- plus the rendered 
> markdown string {{ToMarkdownContentHandler}} already produces (TIKA-4730).
> * *Typed common metadata*: title, authors, keywords, languages, 
> created/modified as {{Timestamp}}s, page/word/character counts, dimensions, 
> rights.
> * *Lossless tagged tail*: every remaining metadata key, 
> multivalue-preserving, typed only where Tika's own {{Property}} declares a 
> type, string otherwise -- never guessed.
> * *Embedded documents* recurse as fully typed child {{Document}}s.
> * Format specifics live in per-parser {{DocumentTransformer}} code 
> ({{tika-grpc-mapper}}), never in the wire contract, so metadata churn never 
> forces a client rebuild.
> Modules: {{tika-grpc-api}} (proto + generated messages + bundled 
> {{FileDescriptorSet}}), {{tika-grpc-mapper}}, {{tika-grpc}} integration. 
> Breaking change for clients reading {{fields}} (field number reserved).
> PR: [https://github.com/apache/tika/pull/2921] (supersedes 
> [#2916|https://github.com/apache/tika/pull/2916])
> Follow-ups will be tracked in separate issues: pluggable external parsers 
> (opaque {{Any}} extension results from registered gRPC services), and a 
> Markdown input parser.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to