Skip to content

Commit

Permalink
upgraded ppt parser by migration of org.apache,poi from 3.17 to 5.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Orbiter committed Jul 21, 2024
1 parent 6878207 commit 833d720
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 32 deletions.
4 changes: 2 additions & 2 deletions ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@
<dependency org="org.apache.lucene" name="lucene-suggest" rev="9.0.0"/>

<dependency org="org.apache.pdfbox" name="pdfbox" rev="3.0.2" />
<dependency org="org.apache.poi" name="poi" rev="3.17" />
<dependency org="org.apache.poi" name="poi-scratchpad" rev="3.17" />
<dependency org="org.apache.poi" name="poi" rev="5.3.0" />
<dependency org="org.apache.poi" name="poi-scratchpad" rev="5.3.0" />

<dependency org="org.apache.solr" name="solr-core" rev="9.0.0" conf="compile->master"/>
<dependency org="org.apache.solr" name="solr-scripting" rev="9.0.0" conf="compile->master"/>
Expand Down
71 changes: 41 additions & 30 deletions source/net/yacy/document/parser/pptParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,14 @@
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.poi.hpsf.DocumentSummaryInformation;
import org.apache.poi.hpsf.SummaryInformation;
import org.apache.poi.hslf.usermodel.HSLFSlideShow;
import org.apache.poi.sl.extractor.SlideShowExtractor;

import net.yacy.cora.document.id.DigestURL;
import net.yacy.cora.util.CommonPattern;
import net.yacy.cora.util.ConcurrentLog;
Expand All @@ -42,8 +48,6 @@
import net.yacy.document.Parser;
import net.yacy.document.VocabularyScraper;

import org.apache.poi.hslf.extractor.PowerPointExtractor;

public class pptParser extends AbstractParser implements Parser {

public pptParser(){
Expand All @@ -69,40 +73,47 @@ public Document[] parse(
final DigestURL location,
final String mimeType,
final String charset,
final VocabularyScraper scraper,
final VocabularyScraper scraper,
final int timezoneOffset,
final InputStream source) throws Parser.Failure,
InterruptedException {
final InputStream source) throws Parser.Failure, InterruptedException {
try {
/*
* create new PowerPointExtractor and extract text and notes
* of the document
*/
final PowerPointExtractor pptExtractor = new PowerPointExtractor(new BufferedInputStream(source));
final String contents = pptExtractor.getText(true, true).trim();
String title = contents.replaceAll("\r"," ").replaceAll("\n"," ").replaceAll("\t"," ").trim();
if (title.length() > 80) title = title.substring(0, 80);
int l = title.length();
while (true) {
title = title.replaceAll(" ", " ");
if (title.length() == l) break;
l = title.length();
final BufferedInputStream bis = new BufferedInputStream(source);
final HSLFSlideShow slideShow = new HSLFSlideShow(bis);
final SummaryInformation summaryInfo = slideShow.getSummaryInformation();
final DocumentSummaryInformation docSummaryInfo = slideShow.getDocumentSummaryInformation();
@SuppressWarnings({ "rawtypes", "unchecked" })
final SlideShowExtractor<?,?> pptExtractor = new SlideShowExtractor(slideShow);
final String contents = pptExtractor.getText().trim();

String title = summaryInfo == null ? "" : summaryInfo.getTitle();
if (title.length() == 0) {
title = contents.replaceAll("\r"," ").replaceAll("\n"," ").replaceAll("\t"," ").trim();
if (title.length() > 80) title = title.substring(0, 80);
int l = title.length();
while (true) {
title = title.replaceAll(" ", " ");
if (title.length() == l) break;
l = title.length();
}
}
// get keywords (for yacy as array)
final String keywords = pptExtractor.getSummaryInformation().getKeywords();

final String author = summaryInfo == null ? "" : summaryInfo.getAuthor();
final String keywords = summaryInfo == null ? "" : summaryInfo.getKeywords();
final String subject = summaryInfo == null ? "" : summaryInfo.getSubject();
//final String comments = summaryInfo == null ? "" : summaryInfo.getComments();
final Date lastSaveDate = summaryInfo == null ? null : summaryInfo.getLastSaveDateTime();
//final String category = docSummaryInfo == null ? "" : docSummaryInfo.getCategory();
final String company = docSummaryInfo == null ? "" : docSummaryInfo.getCompany();
//final String manager = docSummaryInfo == null ? "" : docSummaryInfo.getManager();

final String[] keywlist;
if (keywords != null && !keywords.isEmpty()) {
keywlist = CommonPattern.COMMA.split(keywords);
} else keywlist = null;

final String subject = pptExtractor.getSummaryInformation().getSubject();
List<String> descriptions = new ArrayList<String>();
final List<String> descriptions = new ArrayList<>();
if (subject != null && !subject.isEmpty()) descriptions.add(subject);

/*
* create the plasmaParserDocument for the database
* and set shortText and bodyText properly
*/
final Document[] docs = new Document[]{new Document(
location,
mimeType,
Expand All @@ -111,8 +122,8 @@ public Document[] parse(
null,
keywlist,
singleList(title),
pptExtractor.getSummaryInformation().getAuthor(), // may be null
pptExtractor.getDocSummaryInformation().getCompany(),
author, // may be null
company,
null,
descriptions,
0.0d, 0.0d,
Expand All @@ -121,9 +132,9 @@ public Document[] parse(
null,
null,
false,
pptExtractor.getSummaryInformation().getLastSaveDateTime() // may be null
lastSaveDate // may be null
)};
try {pptExtractor.close();} catch (IOException e1) {}
try {pptExtractor.close();} catch (final IOException e1) {}
return docs;
} catch (final Exception e) {
if (e instanceof InterruptedException) throw (InterruptedException) e;
Expand Down

0 comments on commit 833d720

Please sign in to comment.