mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-19 19:14:55 +00:00
Merge pull request #5675 from wschaeferB/6076-SummarizerApiChanges
6076 summarizer api changes
This commit is contained in:
commit
c7d0f34ac5
@ -78,6 +78,7 @@ import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepository;
|
|||||||
import org.sleuthkit.autopsy.textextractors.TextExtractor;
|
import org.sleuthkit.autopsy.textextractors.TextExtractor;
|
||||||
import org.sleuthkit.autopsy.textextractors.TextExtractorFactory;
|
import org.sleuthkit.autopsy.textextractors.TextExtractorFactory;
|
||||||
import org.sleuthkit.autopsy.textsummarizer.TextSummarizer;
|
import org.sleuthkit.autopsy.textsummarizer.TextSummarizer;
|
||||||
|
import org.sleuthkit.autopsy.textsummarizer.TextSummary;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Main class to perform the file search.
|
* Main class to perform the file search.
|
||||||
@ -258,8 +259,8 @@ class FileSearch {
|
|||||||
*/
|
*/
|
||||||
@NbBundle.Messages({"FileSearch.documentSummary.noPreview=No preview available.",
|
@NbBundle.Messages({"FileSearch.documentSummary.noPreview=No preview available.",
|
||||||
"FileSearch.documentSummary.noBytes=No bytes read for document, unable to display preview."})
|
"FileSearch.documentSummary.noBytes=No bytes read for document, unable to display preview."})
|
||||||
static String summarize(AbstractFile file) {
|
static TextSummary summarize(AbstractFile file) {
|
||||||
String summary = null;
|
TextSummary summary = null;
|
||||||
TextSummarizer localSummarizer = summarizerToUse;
|
TextSummarizer localSummarizer = summarizerToUse;
|
||||||
if (localSummarizer == null) {
|
if (localSummarizer == null) {
|
||||||
synchronized (searchCache) {
|
synchronized (searchCache) {
|
||||||
@ -273,12 +274,12 @@ class FileSearch {
|
|||||||
//a summary of length 40 seems to fit without vertical scroll bars
|
//a summary of length 40 seems to fit without vertical scroll bars
|
||||||
summary = localSummarizer.summarize(file, 40);
|
summary = localSummarizer.summarize(file, 40);
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
return Bundle.FileSearch_documentSummary_noPreview();
|
return new TextSummary(Bundle.FileSearch_documentSummary_noPreview(), null, 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (StringUtils.isBlank(summary)) {
|
if (summary == null || StringUtils.isBlank(summary.getSummaryText())) {
|
||||||
//no summarizer was found or summary was empty just grab the beginning of the file
|
//summary text was empty grab the beginning of the file
|
||||||
summary = getFirstLines(file);
|
summary = new TextSummary(getFirstLines(file), null, 0);
|
||||||
}
|
}
|
||||||
return summary;
|
return summary;
|
||||||
}
|
}
|
||||||
|
@ -55,6 +55,7 @@ import org.sleuthkit.autopsy.modules.hashdatabase.AddContentToHashDbAction;
|
|||||||
import org.sleuthkit.datamodel.AbstractFile;
|
import org.sleuthkit.datamodel.AbstractFile;
|
||||||
import org.sleuthkit.datamodel.TskCoreException;
|
import org.sleuthkit.datamodel.TskCoreException;
|
||||||
import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepository;
|
import org.sleuthkit.autopsy.centralrepository.datamodel.CentralRepository;
|
||||||
|
import org.sleuthkit.autopsy.textsummarizer.TextSummary;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Panel for displaying of file discovery results and handling the paging of
|
* Panel for displaying of file discovery results and handling the paging of
|
||||||
@ -777,11 +778,11 @@ public class ResultsPanel extends javax.swing.JPanel {
|
|||||||
@Messages({"ResultsPanel.unableToCreate.text=Unable to create summary."})
|
@Messages({"ResultsPanel.unableToCreate.text=Unable to create summary."})
|
||||||
@Override
|
@Override
|
||||||
protected Void doInBackground() throws Exception {
|
protected Void doInBackground() throws Exception {
|
||||||
String preview = FileSearch.summarize(documentWrapper.getResultFile().getFirstInstance());
|
TextSummary preview = FileSearch.summarize(documentWrapper.getResultFile().getFirstInstance());
|
||||||
if (preview == null) {
|
if (preview == null) {
|
||||||
preview = Bundle.ResultsPanel_unableToCreate_text();
|
preview = new TextSummary(Bundle.ResultsPanel_unableToCreate_text(), null, 0);
|
||||||
}
|
}
|
||||||
documentWrapper.setPreview(preview);
|
documentWrapper.setPreview(preview.getSummaryText());
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -40,9 +40,9 @@ public interface TextSummarizer {
|
|||||||
* @param file The AbstractFile to summarize.
|
* @param file The AbstractFile to summarize.
|
||||||
* @param summarySize The size of the summary to create.
|
* @param summarySize The size of the summary to create.
|
||||||
*
|
*
|
||||||
* @return The summary as a string.
|
* @return The summary as a TextSummary object.
|
||||||
*
|
*
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
String summarize(AbstractFile file, int summarySize) throws IOException;
|
TextSummary summarize(AbstractFile file, int summarySize) throws IOException;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Autopsy
|
||||||
|
*
|
||||||
|
* Copyright 2020 Basis Technology Corp.
|
||||||
|
* Contact: carrier <at> sleuthkit <dot> org
|
||||||
|
*
|
||||||
|
* Licensed 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.sleuthkit.autopsy.textsummarizer;
|
||||||
|
|
||||||
|
import java.awt.Image;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class to contain all information necessary to display a summary for a file.s
|
||||||
|
*/
|
||||||
|
public class TextSummary {
|
||||||
|
|
||||||
|
private final String summaryText;
|
||||||
|
private final Image sampleImage;
|
||||||
|
private final int numberOfImages;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create a new TextSummary object.
|
||||||
|
*
|
||||||
|
* @param summary - The text portion of the summary.
|
||||||
|
* @param image - The Image portion of the summary
|
||||||
|
* @param countOfImages - The number of images including the one provided in
|
||||||
|
* the document.
|
||||||
|
*/
|
||||||
|
public TextSummary(String summary, Image image, int countOfImages) {
|
||||||
|
summaryText = summary;
|
||||||
|
sampleImage = image;
|
||||||
|
numberOfImages = countOfImages;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the summaryText
|
||||||
|
*/
|
||||||
|
public String getSummaryText() {
|
||||||
|
return summaryText;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the sampleImage
|
||||||
|
*/
|
||||||
|
public Image getSampleImage() {
|
||||||
|
return sampleImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the numberOfImages
|
||||||
|
*/
|
||||||
|
public int getNumberOfImages() {
|
||||||
|
return numberOfImages;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user