@Override public int canEnhance(ContentItem ci) throws EngineException { if (ContentItemHelper.getBlob(ci, SUPPORTED_MIMETYPES) != null) { return ENHANCE_ASYNC; } return CANNOT_ENHANCE; }
@Override public AnalysedText createAnalysedText(Blob blob) throws IOException { String text = ContentItemHelper.getText(blob); return new AnalysedTextImpl(blob,text); } }
public static IRI makeDefaultUri(String baseUri, InputStream in) { // calculate an ID based on the digest of the content if (!baseUri.startsWith("urn:") && !baseUri.endsWith("/")) { baseUri += "/"; } String hexDigest; try { hexDigest = streamDigest(in, null, SHA1); } catch (IOException e) { throw new IllegalStateException("Unable to read content for calculating" + "the hexDigest of the parsed content as used for the default URI" + "of an ContentItem!",e); } IOUtils.closeQuietly(in); return new IRI(baseUri + SHA1.toLowerCase() + "-" + hexDigest); } /**
public static String getPlainContent(ContentItem ci) throws EngineException { Entry<IRI, Blob> contentPart = ContentItemHelper.getBlob(ci, SUPPORTED_MIMTYPES); if (contentPart == null) { throw new IllegalStateException( "No ContentPart with Mimetype '" + TEXT_PLAIN_MIMETYPE + "' found for ContentItem " + ci.getUri() + ": This is also checked in the canEnhance method! -> This " + "indicated an Bug in the implementation of the " + "EnhancementJobManager!"); } try { return ContentItemHelper.getText(contentPart.getValue()); } catch (IOException e) { throw new EngineException("Unable to read plain text content form" + "contentpart "+contentPart.getKey()+" of ContentItem " + ci.getUri()); } } /**
Map<String,Object> reqProp = ContentItemHelper.getRequestPropertiesContentPart(ci); boolean omitMetadata = isOmitMetadata(reqProp); if(!MULTIPART.isCompatible(mediaType)){ //two possible cases Entry<IRI,Blob> contentPart = getBlob(ci, Collections.singleton(mediaType.toString())); if(contentPart == null){ //no alternate content with the requeste media type throw new WebApplicationException("The requested enhancement chain has not created an " for(Entry<IRI,Graph> entry : getContentParts(ci, Graph.class).entrySet()){ if(includeContentParts.isEmpty() || includeContentParts.contains( entry.getKey())){
String mediaTypeString = backend.stringValue(param); try { mimeTypes.add(parseMimeType(mediaTypeString).get(null)); } catch (IllegalArgumentException e) { log.warn(String.format("Invalid mediaType '%s' (based on RFC 2046) parsed!", blob = ci.getBlob(); } else { Entry<IRI,Blob> entry = ContentItemHelper.getBlob(ci, mimeTypes); blob = entry != null ? entry.getValue() : null;
protected FileBlob(ContentSource source) throws IOException { if(source == null){ throw new IllegalArgumentException("The parsed ConentSource MUST NOT be NULL!"); } file = createTempFile("blob"); OutputStream out = null; InputStream in = null; try { out = new FileOutputStream(file); in = source.getStream(); sha1 = ContentItemHelper.streamDigest(in, out, SHA1); } finally { IOUtils.closeQuietly(in); IOUtils.closeQuietly(out); } Map<String,String> parameters; if(source.getMediaType() == null){ this.mimeType = DEFAULT_BINARY_MIMETYPE; parameters = new HashMap<String,String>(); } else { parameters = ContentItemHelper.parseMimeType(source.getMediaType()); this.mimeType = parameters.remove(null); } this.parameters = Collections.unmodifiableMap(parameters); } /**
/** * Creates a {@link RDFBackend} over the {@link ContentItem#getMetadata() * metadata} and all {@link ContentItem#getPart(int, Class) content parts} * compatible to {@link Graph} * @param ci the content item * @param includeAdditionalMetadata if <code>true</code> the {@link RDFBackend} * will also include RDF data stored in content parts */ public ContentItemBackend(ContentItem ci, boolean includeAdditionalMetadata){ included = includeAdditionalMetadata ? unmodifiableMap(getContentParts(ci, Graph.class)) : EMPTY_INCLUDED; Graph graph; if(included.isEmpty()){ graph = ci.getMetadata(); } else { Graph[] tcs = new Graph[included.size()+1]; tcs[0] = ci.getMetadata(); System.arraycopy(included.values().toArray(), 0, tcs, 1, included.size()); graph = new UnionGraph(tcs); } backend = new ClerezzaBackend(graph); this.ci = ci; this.readLock = ci.getLock().readLock(); } /**
Map<String,Object> epContentPart = ContentItemHelper.getRequestPropertiesContentPart(ci); Map<String,Object> chainProperties = new HashMap<String,Object>(); Map<String,Object> engineProperties = new HashMap<String,Object>();
@Override public void computeEnhancements(ContentItem ci) throws EngineException { String language = EnhancementEngineHelper.getLanguage(ci); if (!isLangSupported(language)) { throw new IllegalStateException("Call to computeEnhancement with unsupported language '" + language + " for ContentItem " + ci.getUri() + ": This is also checked " + "in the canEnhance method! -> This indicated an Bug in the " + "implementation of the " + "EnhancementJobManager!"); } Entry<IRI, Blob> contentPart = ContentItemHelper.getBlob(ci, SUPPORTED_MIMTYPES); if (contentPart == null) { throw new IllegalStateException("No ContentPart with Mimetype '" + TEXT_PLAIN_MIMETYPE + "' found for ContentItem " + ci.getUri() + ": This is also checked in the canEnhance method! -> This " + "indicated an Bug in the implementation of the " + "EnhancementJobManager!"); } String text; try { text = ContentItemHelper.getText(contentPart.getValue()); } catch (IOException e) { throw new InvalidContentException(this, ci, e); } if (text.trim().length() == 0) { log.info("No text contained in ContentPart {" + contentPart.getKey() + "} of ContentItem {" + ci.getUri() + "}"); return; } Graph graph = ci.getMetadata(); if (this.completeMorphoAnalysis) { this.addMorphoAnalysisEnhancement(ci, text, language, graph); } else { this.addLemmatizationEnhancement(ci, text, language, graph); } }
Map<String,Object> reqProp = ContentItemHelper.getRequestPropertiesContentPart(ci); boolean omitMetadata = isOmitMetadata(reqProp); if(!MULTIPART.isCompatible(mediaType)){ //two possible cases Entry<IRI,Blob> contentPart = getBlob(ci, Collections.singleton(mediaType.toString())); if(contentPart == null){ //no alternate content with the requeste media type throw new WebApplicationException("The requested enhancement chain has not created an " for(Entry<IRI,Graph> entry : getContentParts(ci, Graph.class).entrySet()){ if(includeContentParts.isEmpty() || includeContentParts.contains( entry.getKey())){
/** * @param ci * @param properties * @return */ private List<Entry<IRI,Blob>> filterBlobs(ContentItem ci, Map<String,Object> properties) { final List<Entry<IRI,Blob>> includedContentPartList; Set<MediaType> includeMediaTypes = getIncludedMediaTypes(properties); if(includeMediaTypes == null){ includedContentPartList = Collections.emptyList(); } else { includedContentPartList = new ArrayList<Map.Entry<IRI,Blob>>(); Set<String> ignoreContentPartUris = getIgnoredContentURIs(properties); nextContentPartEntry: for(Entry<IRI,Blob> entry : getContentParts(ci,Blob.class).entrySet()){ if(!ignoreContentPartUris.contains(entry.getKey().getUnicodeString())){ Blob blob = entry.getValue(); MediaType blobMediaType = MediaType.valueOf(blob.getMimeType()); for(MediaType included : includeMediaTypes) { if(blobMediaType.isCompatible(included)){ includedContentPartList.add(entry); continue nextContentPartEntry; } } } //else ignore this Blob } } return includedContentPartList; } /**
Map<String,Object> epContentPart = ContentItemHelper.getRequestPropertiesContentPart(ci); Map<String,Object> chainProperties = new HashMap<String,Object>(); Map<String,Object> engineProperties = new HashMap<String,Object>();
public void computeEnhancements(ContentItem ci) throws EngineException { Entry<IRI,Blob> contentPart = ContentItemHelper.getBlob(ci, SUPPORTED_MIMETYPES); if(contentPart == null){ throw new IllegalStateException("No ContentPart with an supported Mimetype '" text = ContentItemHelper.getText(contentPart.getValue()); } catch (IOException e) { throw new InvalidContentException(this, ci, e);
@Override public int canEnhance(ContentItem ci) throws EngineException { if (ContentItemHelper.getBlob(ci, SUPPORTED_MIMETYPES) != null) { return ENHANCE_ASYNC; } return CANNOT_ENHANCE; }
@Override public AnalysedText createAnalysedText(Blob blob) throws IOException { String text = ContentItemHelper.getText(blob); return new AnalysedTextImpl(blob,text); } }
public static IRI makeDefaultUri(String baseUri, InputStream in) { // calculate an ID based on the digest of the content if (!baseUri.startsWith("urn:") && !baseUri.endsWith("/")) { baseUri += "/"; } String hexDigest; try { hexDigest = streamDigest(in, null, SHA1); } catch (IOException e) { throw new IllegalStateException("Unable to read content for calculating" + "the hexDigest of the parsed content as used for the default URI" + "of an ContentItem!",e); } IOUtils.closeQuietly(in); return new IRI(baseUri + SHA1.toLowerCase() + "-" + hexDigest); } /**
/** * @param ci * @param properties * @return */ private List<Entry<IRI,Blob>> filterBlobs(ContentItem ci, Map<String,Object> properties) { final List<Entry<IRI,Blob>> includedContentPartList; Set<MediaType> includeMediaTypes = getIncludedMediaTypes(properties); if(includeMediaTypes == null){ includedContentPartList = Collections.emptyList(); } else { includedContentPartList = new ArrayList<Map.Entry<IRI,Blob>>(); Set<String> ignoreContentPartUris = getIgnoredContentURIs(properties); nextContentPartEntry: for(Entry<IRI,Blob> entry : getContentParts(ci,Blob.class).entrySet()){ if(!ignoreContentPartUris.contains(entry.getKey().getUnicodeString())){ Blob blob = entry.getValue(); MediaType blobMediaType = MediaType.valueOf(blob.getMimeType()); for(MediaType included : includeMediaTypes) { if(blobMediaType.isCompatible(included)){ includedContentPartList.add(entry); continue nextContentPartEntry; } } } //else ignore this Blob } } return includedContentPartList; } /**
public void computeEnhancements(ContentItem ci) throws EngineException { Entry<IRI,Blob> contentPart = ContentItemHelper.getBlob(ci, SUPPORTED_MIMTYPES); if(contentPart == null){ throw new IllegalStateException("No ContentPart with Mimetype '" text = ContentItemHelper.getText(contentPart.getValue()); } catch (IOException e) { throw new InvalidContentException(this, ci, e);
@Override public int canEnhance(ContentItem ci) throws EngineException { if (ContentItemHelper.getBlob(ci, SUPPORTED_MIMTYPES) != null) { return ENHANCE_ASYNC; } else { return CANNOT_ENHANCE; } }