<commit_before>package org.icij.extract.parser.emf;

import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.mime.MediaType;
import org.apache.tika.parser.AbstractParser;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.sax.XHTMLContentHandler;
import org.freehep.graphicsio.emf.EMFInputStream;
import org.freehep.graphicsio.emf.EMFTag;
import org.freehep.graphicsio.emf.gdi.*;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.freehep.util.io.Tag;
import org.xml.sax.helpers.AttributesImpl;

import static org.apache.tika.sax.XHTMLContentHandler.XHTML;

public class EMFParser extends AbstractParser {

	private static final Set<MediaType> SUPPORTED_TYPES = Collections.unmodifiableSet(new HashSet<>(Arrays
			.asList(MediaType.application("x-emf"), MediaType.image("emf"))));
	private static final String EMF_MIME_TYPE = "image/emf";
	private static final long serialVersionUID = 5516989102471431040L;

	@Override
	public Set<MediaType> getSupportedTypes(final ParseContext context) {
		return SUPPORTED_TYPES;
	}

	@Override
	public void parse(final InputStream stream, final ContentHandler handler, final Metadata metadata, final
	ParseContext context) throws IOException, SAXException, TikaException {
		metadata.set(Metadata.CONTENT_TYPE, EMF_MIME_TYPE);

		final EMFInputStream input = new EMFInputStream(stream);
		Tag tag;

		final XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
		xhtml.startDocument();

		while ((tag = input.readTag()) != null) {
			if (!(tag instanceof EMFTag)) {
				continue;
			}

			xhtml.startElement(XHTML, "p", "p", new AttributesImpl());

			if ((tag instanceof ExtTextOutA) || (tag instanceof ExtTextOutW)) {
				xhtml.characters(((AbstractExtTextOut) tag).getText().getString());
			}

			xhtml.endElement(XHTML, "p", "p");
		}

		xhtml.endDocument();

		input.close();
	}
}<commit_msg>Don't create empty paragraphs<commit_after>package org.icij.extract.parser.emf;

import org.apache.tika.exception.TikaException;
import org.apache.tika.metadata.Metadata;
import org.apache.tika.mime.MediaType;
import org.apache.tika.parser.AbstractParser;
import org.apache.tika.parser.ParseContext;
import org.apache.tika.sax.XHTMLContentHandler;
import org.freehep.graphicsio.emf.EMFInputStream;
import org.freehep.graphicsio.emf.EMFTag;
import org.freehep.graphicsio.emf.gdi.*;
import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;

import org.freehep.util.io.Tag;
import org.xml.sax.helpers.AttributesImpl;

import static org.apache.tika.sax.XHTMLContentHandler.XHTML;

public class EMFParser extends AbstractParser {

	private static final Set<MediaType> SUPPORTED_TYPES = Collections.unmodifiableSet(new HashSet<>(Arrays
			.asList(MediaType.application("x-emf"), MediaType.image("emf"))));
	private static final String EMF_MIME_TYPE = "image/emf";
	private static final long serialVersionUID = 5516989102471431040L;

	@Override
	public Set<MediaType> getSupportedTypes(final ParseContext context) {
		return SUPPORTED_TYPES;
	}

	@Override
	public void parse(final InputStream stream, final ContentHandler handler, final Metadata metadata, final
	ParseContext context) throws IOException, SAXException, TikaException {
		metadata.set(Metadata.CONTENT_TYPE, EMF_MIME_TYPE);

		final EMFInputStream input = new EMFInputStream(stream);
		Tag tag;

		final XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
		xhtml.startDocument();

		while ((tag = input.readTag()) != null) {
			if (!(tag instanceof EMFTag)) {
				continue;
			}

			if ((tag instanceof ExtTextOutA) || (tag instanceof ExtTextOutW)) {
				xhtml.startElement(XHTML, "p", "p", new AttributesImpl());
				xhtml.characters(((AbstractExtTextOut) tag).getText().getString());
				xhtml.endElement(XHTML, "p", "p");
			}
		}

		xhtml.endDocument();

		input.close();
	}
}
{'fraction_non_alphanumeric': 0.1156382477626001, 'fraction_numerical': 0.008949599623174752, 'mean_word_length': 5.533846153846154, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 6}, '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': '2272384', 'n_tokens_mistral': 1473, 'n_tokens_neox': 1351, 'n_words': 283}