<commit_before>package es.usc.citius.composit.iserve.util;


import es.usc.citius.composit.transformer.wsc.wscxml.InstanceResolver;
import es.usc.citius.composit.transformer.wsc.wscxml.WSCTransformer;
import es.usc.citius.composit.wsc08.data.WSCTest;
import es.usc.citius.composit.wsc08.data.knowledge.WSCXMLKnowledgeBase;
import es.usc.citius.composit.wsc08.data.util.OWLTransformer;
import uk.ac.open.kmi.iserve.api.iServeEngine;
import uk.ac.open.kmi.iserve.sal.manager.ServiceManager;
import uk.ac.open.kmi.msm4j.Service;

import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static net.jadler.Jadler.*;

public class WSCImportUtils {

    public static void importDataset(iServeEngine engine, URL ontologyUrl, WSCTest test, boolean force) throws Exception {
        int services = engine.getRegistryManager().getServiceManager().listServices().size();
        int concepts = engine.getRegistryManager().getKnowledgeBaseManager().listConcepts(ontologyUrl.toURI()).size();
        // TODO: Add #services and #concepts to WSCTest
        if (force || services != test.getServices() || concepts != test.getConcepts()){
            // Clear registry
            engine.getRegistryManager().getServiceManager().clearServices();
            engine.getRegistryManager().getDocumentManager().clearDocuments();
            engine.getRegistryManager().clearRegistry();
            WSCImportUtils.importServices(
                    test.openServicesStream(),
                    ontologyUrl,
                    test.createKnowledgeBase(),
                    engine.getRegistryManager().getServiceManager());
        }
    }

    public static Map<URI, Service> importServices(InputStream servicesStream, URL ontoUrl, final WSCXMLKnowledgeBase kb, ServiceManager mgr) throws Exception {
        // Export kb to OWL
        String ontoOwl = OWLTransformer.convertKbToOwl(kb, ontoUrl.toString());
        // Transform the services to iserve model and import
        InstanceResolver resolver = new InstanceResolver() {
            @Override
            public String resolveToConcept(String s) {
                return kb.resolveInstance(kb.getInstance(s)).getID();
            }<commit_msg>Clearing the registry should also clear services and documents<commit_after>package es.usc.citius.composit.iserve.util;


import es.usc.citius.composit.transformer.wsc.wscxml.InstanceResolver;
import es.usc.citius.composit.transformer.wsc.wscxml.WSCTransformer;
import es.usc.citius.composit.wsc08.data.WSCTest;
import es.usc.citius.composit.wsc08.data.knowledge.WSCXMLKnowledgeBase;
import es.usc.citius.composit.wsc08.data.util.OWLTransformer;
import uk.ac.open.kmi.iserve.api.iServeEngine;
import uk.ac.open.kmi.iserve.sal.manager.ServiceManager;
import uk.ac.open.kmi.msm4j.Service;

import java.io.InputStream;
import java.net.URI;
import java.net.URL;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static net.jadler.Jadler.*;

public class WSCImportUtils {

    public static void importDataset(iServeEngine engine, URL ontologyUrl, WSCTest test, boolean force) throws Exception {
        int services = engine.getRegistryManager().getServiceManager().listServices().size();
        int concepts = engine.getRegistryManager().getKnowledgeBaseManager().listConcepts(ontologyUrl.toURI()).size();
        // TODO: Add #services and #concepts to WSCTest
        if (force || services != test.getServices() || concepts != test.getConcepts()) {
            // Clear registry
            engine.getRegistryManager().clearRegistry();
            WSCImportUtils.importServices(
                    test.openServicesStream(),
                    ontologyUrl,
                    test.createKnowledgeBase(),
                    engine.getRegistryManager().getServiceManager());
        }
    }

    public static Map<URI, Service> importServices(InputStream servicesStream, URL ontoUrl, final WSCXMLKnowledgeBase kb, ServiceManager mgr) throws Exception {
        // Export kb to OWL
        String ontoOwl = OWLTransformer.convertKbToOwl(kb, ontoUrl.toString());
        // Transform the services to iserve model and import
        InstanceResolver resolver = new InstanceResolver() {
            @Override
            public String resolveToConcept(String s) {
                return kb.resolveInstance(kb.getInstance(s)).getID();
            }
{'fraction_non_alphanumeric': 0.10462505612932196, 'fraction_numerical': 0.003143242029636282, 'mean_word_length': 3.2836538461538463, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, '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': '2144139', 'n_tokens_mistral': 1310, 'n_tokens_neox': 1262, 'n_words': 246}