<commit_before>/*
 * Copyright (C) 2012 <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package com.github.fhirschmann.clozegen.lib.adapter;

import com.github.fhirschmann.clozegen.lib.adapter.api.GeneratorAdapter;
import com.github.fhirschmann.clozegen.lib.adapter.api.WriterAdapter;
import com.github.fhirschmann.clozegen.lib.generator.api.GapGenerator;
import com.github.fhirschmann.clozegen.lib.generator.PrepositionGapGenerator;
import com.github.fhirschmann.clozegen.lib.generator.PrepositionGapGeneratorModel;
import com.github.fhirschmann.clozegen.lib.util.UIMAUtils;
import com.github.fhirschmann.clozegen.lib.writer.GapWriter;
import com.github.fhirschmann.clozegen.lib.writer.MultisetWriter;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.google.common.io.Resources;
import de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS;
import de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.PP;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.uima.cas.ConstraintFactory;
import org.apache.uima.cas.FSMatchConstraint;
import org.apache.uima.cas.FSTypeConstraint;
import org.apache.uima.jcas.tcas.Annotation;
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.resource.ResourceSpecifier;
import org.uimafit.component.Resource_ImplBase;
import org.uimafit.descriptor.ConfigurationParameter;

/**
 * This annotator creates annotations for prepositions.
 *
 * @author <NAME> <<EMAIL>>
 */
public class PrepositionAdapter extends Resource_ImplBase implements GeneratorAdapter,
        WriterAdapter {
    /** The path to the preposition collocations. */
    public static final String PARAM_PATH = "Path";
    @ConfigurationParameter(name = PARAM_PATH, mandatory = true)
    private String path;

    private PrepositionGapGeneratorModel model;

    @Override
	public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
            throws ResourceInitializationException {
        if (!super.initialize(aSpecifier, aAdditionalParams)) {
            return false;
        }

        model = new PrepositionGapGeneratorModel();
        try {
            model.load(Resources.getResource(path + "/trigrams.txt"),
                    Resources.getResource(path + "/after.txt"),
                    Resources.getResource(path + "/before.txt"));
            return true;
        } catch (IOException ex) {
            Logger.getLogger(PrepositionAdapter.class.getName()).
                    log(Level.SEVERE, null, ex);
            return false;
        }
    }

    @Override
    public FSMatchConstraint getConstraint() {
        FSTypeConstraint cons = ConstraintFactory.instance().createTypeConstraint();
        cons.add(PP.class.getName());
        return cons;
    }

    @Override
    public GapGenerator generator(
            final List<Annotation> annotationList, final int offset) {
        List<String> tokens = UIMAUtils.getAdjacentTokens(POS.class,
                annotationList, offset, 1);

        return PrepositionGapGenerator.create(
                tokens.get(0), tokens.get(1), tokens.get(2), model);
    }

    @Override
    public Set<GapWriter> writer(final List<Annotation> annotationList, final int offset) {
        List<String> tokens = UIMAUtils.getAdjacentTokens(POS.class,
                annotationList, offset, 1);
        Set<GapWriter> writers = Sets.newHashSet();
        return writers;
    }
}<commit_msg>[lib] removed writer stuff (for now)<commit_after>/*
 * Copyright (C) 2012 <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package com.github.fhirschmann.clozegen.lib.adapter;

import com.github.fhirschmann.clozegen.lib.adapter.api.GeneratorAdapter;
import com.github.fhirschmann.clozegen.lib.generator.api.GapGenerator;
import com.github.fhirschmann.clozegen.lib.generator.PrepositionGapGenerator;
import com.github.fhirschmann.clozegen.lib.generator.PrepositionGapGeneratorModel;
import com.github.fhirschmann.clozegen.lib.util.UIMAUtils;
import com.github.fhirschmann.clozegen.lib.writer.GapWriter;
import com.google.common.io.Resources;
import de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.POS;
import de.tudarmstadt.ukp.dkpro.core.api.lexmorph.type.pos.PP;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.uima.cas.ConstraintFactory;
import org.apache.uima.cas.FSMatchConstraint;
import org.apache.uima.cas.FSTypeConstraint;
import org.apache.uima.jcas.tcas.Annotation;
import org.apache.uima.resource.ResourceInitializationException;
import org.apache.uima.resource.ResourceSpecifier;
import org.uimafit.component.Resource_ImplBase;
import org.uimafit.descriptor.ConfigurationParameter;

/**
 * This annotator creates annotations for prepositions.
 *
 * @author <NAME> <<EMAIL>>
 */
public class PrepositionAdapter extends Resource_ImplBase implements GeneratorAdapter {
    /** The path to the preposition collocations. */
    public static final String PARAM_PATH = "Path";
    @ConfigurationParameter(name = PARAM_PATH, mandatory = true)
    private String path;

    private PrepositionGapGeneratorModel model;
    private GapWriter writer;

    @Override
	public boolean initialize(ResourceSpecifier aSpecifier, Map<String, Object> aAdditionalParams)
            throws ResourceInitializationException {
        if (!super.initialize(aSpecifier, aAdditionalParams)) {
            return false;
        }

        model = new PrepositionGapGeneratorModel();
        try {
            model.load(Resources.getResource(path + "/trigrams.txt"),
                    Resources.getResource(path + "/after.txt"),
                    Resources.getResource(path + "/before.txt"));
            return true;
        } catch (IOException ex) {
            Logger.getLogger(PrepositionAdapter.class.getName()).
                    log(Level.SEVERE, null, ex);
            return false;
        }
    }

    @Override
    public FSMatchConstraint getConstraint() {
        FSTypeConstraint cons = ConstraintFactory.instance().createTypeConstraint();
        cons.add(PP.class.getName());
        return cons;
    }

    @Override
    public GapGenerator generator(
            final List<Annotation> annotationList, final int offset) {
        List<String> tokens = UIMAUtils.getAdjacentTokens(POS.class,
                annotationList, offset, 1);

        return PrepositionGapGenerator.create(
                tokens.get(0), tokens.get(1), tokens.get(2), model);
    }
}
{'fraction_non_alphanumeric': 0.09497206703910614, 'fraction_numerical': 0.005834885164494103, 'mean_word_length': 3.5643059490084985, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 25, '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': '5016188', 'n_tokens_mistral': 2306, 'n_tokens_neox': 2244, 'n_words': 581}