<commit_before>package org.apache.clerezza.uima.metadatagenerator;

import org.apache.clerezza.rdf.core.LiteralFactory;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.metadata.MetaDataGenerator;
import org.apache.clerezza.rdf.ontologies.DC;
import org.apache.clerezza.rdf.ontologies.DCTERMS;
import org.apache.clerezza.rdf.utils.GraphNode;
import org.apache.clerezza.uima.utils.ExternalServicesFacade;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.apache.uima.UIMAException;

import javax.ws.rs.core.MediaType;

/**
 * 
 * An implementation of <code>MetaDataGenerator</code> generates meta data about specified data
 * depending on its media type using UIMA.
 * 
 */
@Component()
@Service(MetaDataGenerator.class)
public class UIMABaseMetadataGenerator implements MetaDataGenerator {

  private ExternalServicesFacade facade = new ExternalServicesFacade();

  @Override
  public void generate(GraphNode node, byte[] data, MediaType mediaType) {
    // FIXME only TEXT_PLAIN, also different MediaTypes should be served
    if (MediaType.TEXT_PLAIN.equals(mediaType.getType())) {
      try {
        //add language to the document
        addLanguage(node, data);
        addCategory(node, data);
        
      } catch (Throwable e) {
        // quietly react to errors
      }
    }
  }

  private void addCategory(GraphNode node, byte[] data) throws UIMAException {
    // get category to bind it to the node
    String category = facade.getCategory(data.toString());
    addStringLiteral(category, node, DC.subject);
  }

  private void addLanguage(GraphNode node, byte[] data) throws UIMAException {
    // get language to bind to the node
    String language = facade.getLanguage(data.toString());
    addStringLiteral(language, node, DCTERMS.language);
  }

  private void addStringLiteral(String value, GraphNode node, UriRef uriRef) {
    node.addProperty(uriRef, LiteralFactory.getInstance().createTypedLiteral(value));
  }

}<commit_msg>[CLEREZZA-193] - as CLEREZZA-212 switched to GraphNode addPropertyValue instead of private similar method<commit_after>package org.apache.clerezza.uima.metadatagenerator;

import org.apache.clerezza.rdf.metadata.MetaDataGenerator;
import org.apache.clerezza.rdf.ontologies.DC;
import org.apache.clerezza.rdf.ontologies.DCTERMS;
import org.apache.clerezza.rdf.utils.GraphNode;
import org.apache.clerezza.uima.utils.ExternalServicesFacade;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Service;
import org.apache.uima.UIMAException;

import javax.ws.rs.core.MediaType;

/**
 * 
 * An implementation of <code>MetaDataGenerator</code> generates meta data about specified data
 * depending on its media type using UIMA.
 * 
 */
@Component()
@Service(MetaDataGenerator.class)
public class UIMABaseMetadataGenerator implements MetaDataGenerator {

  private ExternalServicesFacade facade = new ExternalServicesFacade();

  @Override
  public void generate(GraphNode node, byte[] data, MediaType mediaType) {
    // FIXME only TEXT_PLAIN, also different MediaTypes should be served
    if (MediaType.TEXT_PLAIN.equals(mediaType.getType())) {
      try {
        // add language to the document
        addLanguage(node, data);
        // add wide purpose subject to the document
        addCategory(node, data);
        
      } catch (Throwable e) {
        // quietly react to errors
      }
    }
  }

  private void addCategory(GraphNode node, byte[] data) throws UIMAException {
    // get category to bind it to the node
    String category = facade.getCategory(data.toString());
    node.addPropertyValue(DC.subject,category);
  }

  private void addLanguage(GraphNode node, byte[] data) throws UIMAException {
    // get language to bind to the node
    String language = facade.getLanguage(data.toString());
    node.addPropertyValue(DCTERMS.language,language);
  }

}
{'fraction_non_alphanumeric': 0.09714141158613711, 'fraction_numerical': 0.0015178345560333923, 'mean_word_length': 4.115135834411384, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3640321', 'n_tokens_mistral': 1164, 'n_tokens_neox': 1160, 'n_words': 286}