index
int64
repo_id
string
file_path
string
content
string
0
java-sources/ai/hyacinth/framework/core-service-trigger-server/0.5.24/ai/hyacinth/core/service/trigger/server/service
java-sources/ai/hyacinth/framework/core-service-trigger-server/0.5.24/ai/hyacinth/core/service/trigger/server/service/impl/SpringBeanJobFactory.java
package ai.hyacinth.core.service.trigger.server.service.impl; import org.quartz.spi.TriggerFiredBundle; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.scheduling.quartz.AdaptableJobFactory; import org.springframework.stereotype.Component; @Component public class SpringBeanJobFactory extends AdaptableJobFactory { @Autowired private ApplicationContext ctx; @Override protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception { Object jobInstance = super.createJobInstance(bundle); ctx.getAutowireCapableBeanFactory().autowireBean(jobInstance); return jobInstance; } }
0
java-sources/ai/hyacinth/framework/core-service-trigger-server/0.5.24/ai/hyacinth/core/service/trigger/server/service
java-sources/ai/hyacinth/framework/core-service-trigger-server/0.5.24/ai/hyacinth/core/service/trigger/server/service/impl/TriggerClientService.java
package ai.hyacinth.core.service.trigger.server.service.impl; public interface TriggerClientService { void trigger(Long triggerId); }
0
java-sources/ai/hyacinth/framework/core-service-trigger-server/0.5.24/ai/hyacinth/core/service/trigger/server/service
java-sources/ai/hyacinth/framework/core-service-trigger-server/0.5.24/ai/hyacinth/core/service/trigger/server/service/impl/TriggerClientServiceImpl.java
package ai.hyacinth.core.service.trigger.server.service.impl; import ai.hyacinth.core.service.trigger.server.dto.TriggerInfo; import ai.hyacinth.core.service.trigger.server.dto.type.ServiceTriggerMethodType; import ai.hyacinth.core.service.trigger.server.error.TriggerServiceErrorCode; import ai.hyacinth.core.service.trigger.server.service.TriggerService; import ai.hyacinth.core.service.web.common.ServiceApiException; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.ApplicationContext; import org.springframework.http.HttpHeaders; import org.springframework.http.MediaType; import org.springframework.stereotype.Service; import org.springframework.web.reactive.function.BodyInserters; import org.springframework.web.reactive.function.client.WebClient; @Slf4j @Service public class TriggerClientServiceImpl implements TriggerClientService { @Autowired private TriggerService triggerService; @Autowired private ApplicationContext applicationContext; @Autowired private WebClient.Builder webClientBuilder; // public interface TriggerClient { // @RequestMapping( // path = {"{path}"}, // method = {RequestMethod.POST}, // consumes = {MediaType.APPLICATION_JSON_UTF8_VALUE, MediaType.APPLICATION_JSON_VALUE}) // String triggerCall(@PathVariable("path") String path); // } // @PostConstruct // public void setupFeignClientBuilder() { // FeignClientBuilder feignClientBuilder = new FeignClientBuilder(applicationContext); // } @Override public void trigger(Long triggerId) { log.info("start trigger, ID: {}", triggerId); TriggerInfo sti = triggerService.findTriggerById(triggerId); if (sti == null) { log.error("cannot find trigger, deleted? ID: {}", triggerId); throw new ServiceApiException(TriggerServiceErrorCode.TRIGGER_NOT_FOUND); } else { log.info("start trigger, detail: {}", sti); } if (sti.isEnabled()) { switch (sti.getTriggerMethod()) { case LOG: log.info("trigger logged"); break; case SERVICE_URL: case URL: try { String response = httpRequest(sti); log.info("trigger response: {}", response); } catch (Exception httpException) { log.error("trigger url error", httpException); } break; default: throw new UnsupportedOperationException( "Cannot support trigger method:" + sti.getTriggerMethod()); } } else { log.info("trigger disabled, no action. ID: {} ", triggerId); } } protected String httpRequest(TriggerInfo sti) { WebClient webClient; if (sti.getTriggerMethod().equals(ServiceTriggerMethodType.SERVICE_URL)) { webClient = webClientBuilder .baseUrl("http://" + sti.getService()) .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .build(); } else { webClient = WebClient.builder() .baseUrl(sti.getUrl()) .defaultHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE) .build(); } return webClient .method(sti.getHttpMethod()) .uri(sti.getUrl()) .body( sti.getParams() == null ? BodyInserters.empty() : BodyInserters.fromValue(sti.getParams())) .retrieve() .bodyToMono(String.class) .block(); } }
0
java-sources/ai/hyacinth/framework/core-service-trigger-server/0.5.24/ai/hyacinth/core/service/trigger/server/service
java-sources/ai/hyacinth/framework/core-service-trigger-server/0.5.24/ai/hyacinth/core/service/trigger/server/service/impl/TriggerJobBean.java
package ai.hyacinth.core.service.trigger.server.service.impl; import lombok.extern.slf4j.Slf4j; import org.quartz.JobDetail; import org.quartz.JobExecutionContext; import org.quartz.JobKey; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.scheduling.quartz.QuartzJobBean; import org.springframework.stereotype.Service; @Slf4j @Service public class TriggerJobBean extends QuartzJobBean { @Autowired private TriggerClientService triggerService; public TriggerJobBean() { super(); } public void executeInternal(JobExecutionContext context) { JobDetail jobDetail = context.getJobDetail(); JobKey jobKey = jobDetail.getKey(); Long triggerId = jobDetail.getJobDataMap().getLong(TriggerServiceConstants.JOB_DATA_KEY_TRIGGER_ID); log.info("TriggerJob started, job-key: {}, triggerId: {}", jobKey, triggerId); triggerService.trigger(triggerId); } }
0
java-sources/ai/hyacinth/framework/core-service-trigger-server/0.5.24/ai/hyacinth/core/service/trigger/server/service
java-sources/ai/hyacinth/framework/core-service-trigger-server/0.5.24/ai/hyacinth/core/service/trigger/server/service/impl/TriggerServiceConstants.java
package ai.hyacinth.core.service.trigger.server.service.impl; public interface TriggerServiceConstants { String JOB_DATA_KEY_TRIGGER_ID = "TriggerService/Trigger/Id"; String SERVICE_GLOBAL = "__GLOBAL__"; String EVENT_TYPE = "TriggerService/Event/Trigger"; }
0
java-sources/ai/hyacinth/framework/core-service-trigger-server/0.5.24/ai/hyacinth/core/service/trigger/server/service
java-sources/ai/hyacinth/framework/core-service-trigger-server/0.5.24/ai/hyacinth/core/service/trigger/server/service/impl/TriggerServiceImpl.java
package ai.hyacinth.core.service.trigger.server.service.impl; import ai.hyacinth.core.service.trigger.server.domain.ServiceTrigger; import ai.hyacinth.core.service.trigger.server.dto.TriggerChangeResult; import ai.hyacinth.core.service.trigger.server.dto.TriggerCreationRequest; import ai.hyacinth.core.service.trigger.server.dto.TriggerInfo; import ai.hyacinth.core.service.trigger.server.dto.TriggerQueryRequest; import ai.hyacinth.core.service.trigger.server.dto.TriggerUpdateRequest; import ai.hyacinth.core.service.trigger.server.dto.type.ServiceTriggerMethodType; import ai.hyacinth.core.service.trigger.server.error.TriggerServiceErrorCode; import ai.hyacinth.core.service.trigger.server.repo.ServiceTriggerRepository; import ai.hyacinth.core.service.trigger.server.service.TriggerService; import ai.hyacinth.core.service.web.common.ServiceApiException; import java.util.List; import java.util.Optional; import java.util.function.Supplier; import java.util.stream.Collectors; import lombok.extern.slf4j.Slf4j; import org.quartz.CronScheduleBuilder; import org.quartz.CronTrigger; import org.quartz.Job; import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.JobKey; import org.quartz.Scheduler; import org.quartz.SchedulerException; import org.quartz.TriggerBuilder; import org.quartz.TriggerKey; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.context.properties.PropertyMapper; import org.springframework.data.domain.Example; import org.springframework.lang.NonNull; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import org.springframework.util.StringUtils; @Slf4j @Service public class TriggerServiceImpl implements TriggerService { @Autowired private Scheduler scheduler; @Autowired private ServiceTriggerRepository triggerRepo; private Supplier<ServiceApiException> TRIGGER_NOT_FOUND = () -> new ServiceApiException(TriggerServiceErrorCode.TRIGGER_NOT_FOUND); @Override @Transactional @NonNull public TriggerChangeResult removeTrigger(Long triggerId) { return triggerRepo .findById(triggerId) .map(this::removeQuartzJob) .map( (completed) -> { if (completed) { triggerRepo.deleteById(triggerId); } return new TriggerChangeResult(triggerId, completed); }) .orElseThrow(TRIGGER_NOT_FOUND); } @Override @Transactional @NonNull public TriggerInfo createTrigger(TriggerCreationRequest request) { ServiceTriggerMethodType triggerMethod = request.getTriggerMethod(); if (triggerMethod == null) { triggerMethod = detectTriggerMethodType(request); } String service = request.getService(); if (StringUtils.isEmpty(service)) { service = TriggerServiceConstants.SERVICE_GLOBAL; } Optional<ServiceTrigger> st = triggerRepo.findByServiceAndName(service, request.getName()); if (st.isPresent()) { throw new ServiceApiException(TriggerServiceErrorCode.TRIGGER_EXISTS); } ServiceTrigger serviceTrigger = ServiceTrigger.builder() .name(request.getName()) .cron(request.getCron()) .service(service) .url(request.getUrl()) .triggerMethod(triggerMethod) .httpMethod(request.getHttpMethod()) .params(request.getParams()) .enabled(true) .timeout(request.getTimeout()) .build(); triggerRepo.save(serviceTrigger); addQuartzJob(serviceTrigger); log.info("service trigger created: {}", serviceTrigger); return toDto(serviceTrigger); } private ServiceTriggerMethodType detectTriggerMethodType(TriggerCreationRequest request) { ServiceTriggerMethodType triggerMethod = null; boolean serviceEmtpy = StringUtils.isEmpty(request.getService()); boolean urlEmpty = StringUtils.isEmpty(request.getUrl()); if (serviceEmtpy && !urlEmpty) { triggerMethod = ServiceTriggerMethodType.URL; } if (!serviceEmtpy && urlEmpty) { triggerMethod = ServiceTriggerMethodType.BUS_EVENT; } if (!serviceEmtpy && !urlEmpty) { triggerMethod = ServiceTriggerMethodType.SERVICE_URL; } return triggerMethod; } @Override @Transactional(readOnly = true) public TriggerInfo findTriggerById(Long id) { return triggerRepo.findById(id).map(this::toDto).orElseThrow(TRIGGER_NOT_FOUND); } @Override @Transactional(readOnly = true) public TriggerInfo findTriggerByServiceAndName(String service, String name) { return triggerRepo .findByServiceAndName(service, name) .map(this::toDto) .orElseThrow(TRIGGER_NOT_FOUND); } @Override @Transactional(readOnly = true) @NonNull public List<TriggerInfo> findAllTriggers(TriggerQueryRequest queryRequest) { ServiceTrigger stExample = ServiceTrigger.builder() .name(queryRequest.getName()) .service(queryRequest.getService()) .id(queryRequest.getId()) .build(); return triggerRepo.findAll(Example.of(stExample)).stream() .map(this::toDto) .collect(Collectors.toList()); } @Override @Transactional public TriggerInfo updateTrigger(Long triggerId, TriggerUpdateRequest updateRequest) { return triggerRepo .findById(triggerId) .map( (st) -> { boolean cronChanged = false; if (updateRequest.getCron() != null && !updateRequest.getCron().equals(st.getCron())) { cronChanged = true; } PropertyMapper mapper = PropertyMapper.get(); mapper.from(updateRequest::getCron).whenNonNull().to(st::setCron); mapper.from(updateRequest::getEnabled).whenNonNull().to(st::setEnabled); mapper.from(updateRequest::getTimeout).whenNonNull().to(st::setTimeout); triggerRepo.save(st); if (cronChanged) { updateQuartzJob(st); } return st; }) .map(this::toDto) .orElseThrow(TRIGGER_NOT_FOUND); } private TriggerInfo toDto(ServiceTrigger serviceTrigger) { return TriggerInfo.builder() .id(serviceTrigger.getId()) .name(serviceTrigger.getName()) .timeout(serviceTrigger.getTimeout()) .service(serviceTrigger.getService()) .cron(serviceTrigger.getCron()) .triggerMethod(serviceTrigger.getTriggerMethod()) .url(serviceTrigger.getUrl()) .httpMethod(serviceTrigger.getHttpMethod()) .params(serviceTrigger.getParams()) .enabled(serviceTrigger.getEnabled()) .build(); } private boolean updateQuartzJob(ServiceTrigger serviceTrigger) { try { scheduler.rescheduleJob( TriggerKey.triggerKey(serviceTrigger.getName(), serviceTrigger.getService()), createQuartzTrigger(serviceTrigger)); return true; } catch (SchedulerException ex) { throw new ServiceApiException(TriggerServiceErrorCode.QUARTZ_ERROR, ex); } } private boolean removeQuartzJob(ServiceTrigger st) { JobKey key = JobKey.jobKey(st.getName(), st.getService()); try { return scheduler.deleteJob(key); } catch (SchedulerException ex) { throw new ServiceApiException(TriggerServiceErrorCode.QUARTZ_ERROR, ex); } } private void addQuartzJob(ServiceTrigger serviceTrigger) { final Class<? extends Job> quartzJobClass = TriggerJobBean.class; JobDetail jobDetail = JobBuilder.newJob() .withIdentity(serviceTrigger.getName(), serviceTrigger.getService()) .usingJobData(TriggerServiceConstants.JOB_DATA_KEY_TRIGGER_ID, serviceTrigger.getId()) .ofType(quartzJobClass) .build(); CronTrigger trigger = createQuartzTrigger(serviceTrigger); try { scheduler.scheduleJob(jobDetail, trigger); log.info( "scheduler status, is shutdown: {}, is standby: {}", scheduler.isShutdown(), scheduler.isInStandbyMode()); } catch (SchedulerException ex) { throw new ServiceApiException(TriggerServiceErrorCode.QUARTZ_ERROR, ex); } } private CronTrigger createQuartzTrigger(ServiceTrigger serviceTrigger) { return TriggerBuilder.newTrigger() .withIdentity(serviceTrigger.getName(), serviceTrigger.getService()) .withSchedule(CronScheduleBuilder.cronSchedule(serviceTrigger.getCron())) .startNow() .build(); } }
0
java-sources/ai/hyacinth/framework/core-service-trigger-server/0.5.24/ai/hyacinth/core/service/trigger/server
java-sources/ai/hyacinth/framework/core-service-trigger-server/0.5.24/ai/hyacinth/core/service/trigger/server/web/TriggerController.java
package ai.hyacinth.core.service.trigger.server.web; import ai.hyacinth.core.service.trigger.server.dto.TriggerChangeResult; import ai.hyacinth.core.service.trigger.server.dto.TriggerCreationRequest; import ai.hyacinth.core.service.trigger.server.dto.TriggerInfo; import ai.hyacinth.core.service.trigger.server.dto.TriggerQueryRequest; import ai.hyacinth.core.service.trigger.server.dto.TriggerUpdateRequest; import ai.hyacinth.core.service.trigger.server.service.TriggerService; import ai.hyacinth.core.service.web.common.ServiceApiConstants; import java.util.List; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RestController; @Slf4j @RestController @RequestMapping(ServiceApiConstants.API_PREFIX) public class TriggerController { @Autowired private TriggerService triggerService; @PostMapping(value = "/triggers") public TriggerInfo createTrigger( @Validated @RequestBody TriggerCreationRequest createRequest) { return triggerService.createTrigger(createRequest); } @GetMapping(value = "/triggers") public List<TriggerInfo> findTriggers(TriggerQueryRequest queryRequest) { return triggerService.findAllTriggers(queryRequest); } @RequestMapping( method = {RequestMethod.GET}, value = "/triggers/{triggerId}") public TriggerInfo findTrigger(@PathVariable Long triggerId) { return triggerService.findTriggerById(triggerId); } @RequestMapping( method = {RequestMethod.DELETE}, value = "/triggers/{triggerId}") public TriggerChangeResult removeTrigger(@PathVariable Long triggerId) { return triggerService.removeTrigger(triggerId); } @RequestMapping( method = {RequestMethod.PATCH}, value = "/triggers/{triggerId}") public TriggerInfo updateTrigger( @PathVariable Long triggerId, @Validated @RequestBody TriggerUpdateRequest updateRequest) { return triggerService.updateTrigger(triggerId, updateRequest); } }
0
java-sources/ai/hyacinth/framework/core-service-web-common/0.5.24/ai/hyacinth/core/service/web
java-sources/ai/hyacinth/framework/core-service-web-common/0.5.24/ai/hyacinth/core/service/web/common/ServiceApiConstants.java
package ai.hyacinth.core.service.web.common; public interface ServiceApiConstants { String API_PREFIX = "/api"; String HTTP_HEADER_AUTHENTICATED_PRINCIPLE = "X-Principle"; }
0
java-sources/ai/hyacinth/framework/core-service-web-common/0.5.24/ai/hyacinth/core/service/web
java-sources/ai/hyacinth/framework/core-service-web-common/0.5.24/ai/hyacinth/core/service/web/common/ServiceApiErrorCode.java
package ai.hyacinth.core.service.web.common; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; public interface ServiceApiErrorCode { String getCode(); default String getMessage() { return toString(); } int getHttpStatusCode(); @Data @AllArgsConstructor @NoArgsConstructor class SimpleServiceApiErrorCodeImpl implements ServiceApiErrorCode { protected String code; protected String message; protected int httpStatusCode; } static ServiceApiErrorCode of(String code, String message, int httpStatusCode) { return new SimpleServiceApiErrorCodeImpl(code, message, httpStatusCode); } }
0
java-sources/ai/hyacinth/framework/core-service-web-common/0.5.24/ai/hyacinth/core/service/web
java-sources/ai/hyacinth/framework/core-service-web-common/0.5.24/ai/hyacinth/core/service/web/common/ServiceApiErrorResponse.java
package ai.hyacinth.core.service.web.common; import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonInclude.Include; import lombok.Data; import lombok.EqualsAndHashCode; import java.util.Date; @Data @EqualsAndHashCode(callSuper = true) public class ServiceApiErrorResponse extends ServiceApiResponse { protected String code; protected String message; // the following fields are filled by exception handler private Date timestamp; @JsonInclude(Include.NON_NULL) private String path; @JsonInclude(Include.NON_NULL) private String service; public ServiceApiErrorResponse() { this.status = "error"; } }
0
java-sources/ai/hyacinth/framework/core-service-web-common/0.5.24/ai/hyacinth/core/service/web
java-sources/ai/hyacinth/framework/core-service-web-common/0.5.24/ai/hyacinth/core/service/web/common/ServiceApiException.java
package ai.hyacinth.core.service.web.common; public class ServiceApiException extends RuntimeException { private int httpStatusCode; private ServiceApiErrorResponse errorResponse; public ServiceApiException() { super(); } public ServiceApiException( int httpStatus, ServiceApiErrorResponse errorResponse, Throwable throwable) { super(errorResponse.getMessage(), throwable); this.httpStatusCode = httpStatus; this.errorResponse = errorResponse; } public ServiceApiException(int httpStatus, ServiceApiErrorResponse errorResponse) { this(httpStatus, errorResponse, null); } public ServiceApiException(ServiceApiErrorCode errorCode, Throwable throwable) { this(errorCode.getHttpStatusCode(), createErrorResponse(errorCode, null), throwable); } public ServiceApiException(ServiceApiErrorCode errorCode, Object data) { this(errorCode.getHttpStatusCode(), createErrorResponse(errorCode, data), null); } public ServiceApiException(ServiceApiErrorCode errorCode) { this(errorCode, null); } private static ServiceApiErrorResponse createErrorResponse( ServiceApiErrorCode errorCode, Object data) { ServiceApiErrorResponse response = new ServiceApiErrorResponse(); response.setCode(errorCode.getCode()); response.setMessage(errorCode.getMessage()); response.setData(data); return response; } public int getHttpStatusCode() { return httpStatusCode; } public void setHttpStatusCode(int httpStatusCode) { this.httpStatusCode = httpStatusCode; } public ServiceApiErrorResponse getErrorResponse() { return errorResponse; } }
0
java-sources/ai/hyacinth/framework/core-service-web-common/0.5.24/ai/hyacinth/core/service/web
java-sources/ai/hyacinth/framework/core-service-web-common/0.5.24/ai/hyacinth/core/service/web/common/ServiceApiResponse.java
package ai.hyacinth.core.service.web.common; import com.fasterxml.jackson.annotation.JsonInclude; import lombok.Data; import lombok.NoArgsConstructor; @Data @NoArgsConstructor public class ServiceApiResponse { protected String status = "success"; @JsonInclude(JsonInclude.Include.NON_NULL) protected Object data; }
0
java-sources/ai/hyacinth/framework/core-service-web-common/0.5.24/ai/hyacinth/core/service/web/common
java-sources/ai/hyacinth/framework/core-service-web-common/0.5.24/ai/hyacinth/core/service/web/common/error/CommonServiceErrorCode.java
package ai.hyacinth.core.service.web.common.error; import ai.hyacinth.core.service.web.common.ServiceApiErrorCode; import lombok.AllArgsConstructor; import lombok.Getter; import org.springframework.http.HttpStatus; @Getter @AllArgsConstructor public enum CommonServiceErrorCode implements ServiceApiErrorCode { BAD_REQUEST(HttpStatus.BAD_REQUEST, "E90400"), FORBIDDEN(HttpStatus.FORBIDDEN, "E90403"), NOT_FOUND(HttpStatus.NOT_FOUND, "E90404"), METHOD_NOT_ALLOWED(HttpStatus.METHOD_NOT_ALLOWED, "E90405"), CONFLICT(HttpStatus.CONFLICT, "E90409"), PRECONDITION_FAILED(HttpStatus.PRECONDITION_FAILED, "E90412"), UNSUPPORTED_MEDIA_TYPE(HttpStatus.UNSUPPORTED_MEDIA_TYPE, "E90415"), UNKNOWN_ERROR(HttpStatus.BAD_REQUEST, "E80000"), REQUEST_ERROR(HttpStatus.BAD_REQUEST, "E80100"), // incorrect request parameter or payload NETWORK_ERROR(HttpStatus.BAD_REQUEST, "E80200"), INTERNAL_ERROR(HttpStatus.BAD_REQUEST, "E80300"), ; private HttpStatus httpStatus; private String code; @Override public int getHttpStatusCode() { return httpStatus.value(); } }
0
java-sources/ai/hyacinth/framework/core-service-web-common/0.5.24/ai/hyacinth/core/service/web/common
java-sources/ai/hyacinth/framework/core-service-web-common/0.5.24/ai/hyacinth/core/service/web/common/payload/AuthenticationResult.java
package ai.hyacinth.core.service.web.common.payload; import java.io.Serializable; import java.util.List; import javax.validation.constraints.NotNull; import lombok.Data; import lombok.NoArgsConstructor; @Data @NoArgsConstructor public class AuthenticationResult<PrincipalType> implements Serializable { private static final long serialVersionUID = -214526789160927487L; @NotNull private List<String> authorities; @NotNull private PrincipalType principal; }
0
java-sources/ai/hyacinth/framework/core-service-web-support/0.5.24/ai/hyacinth/core/service/web/support
java-sources/ai/hyacinth/framework/core-service-web-support/0.5.24/ai/hyacinth/core/service/web/support/config/DefaultConfigLoader.java
package ai.hyacinth.core.service.web.support.config; import ai.hyacinth.core.service.module.loader.ConfigLoaderPostProcessor; public class DefaultConfigLoader extends ConfigLoaderPostProcessor {}
0
java-sources/ai/hyacinth/framework/core-service-web-support/0.5.24/ai/hyacinth/core/service/web/support
java-sources/ai/hyacinth/framework/core-service-web-support/0.5.24/ai/hyacinth/core/service/web/support/config/WebConfig.java
package ai.hyacinth.core.service.web.support.config; import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; import org.springframework.context.annotation.Configuration; @Configuration @ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.SERVLET) public class WebConfig {}
0
java-sources/ai/idylnlp/idylnlp-dl4j/1.1.0/ai/idylnlp
java-sources/ai/idylnlp/idylnlp-dl4j/1.1.0/ai/idylnlp/dl4j/IdylNLPTokenizer.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.dl4j; import java.util.Arrays; import java.util.List; import org.deeplearning4j.text.tokenization.tokenizer.TokenPreProcess; import org.deeplearning4j.text.tokenization.tokenizer.Tokenizer; /** * Implements {@link Tokenizer} to wrap Idyl NLP's tokenizer * for use with DeepLearning4j. * * @author Mountain Fog, Inc. * */ public class IdylNLPTokenizer implements Tokenizer { private String[] tokens; private int index = 0; private TokenPreProcess preProcessor; /** * Creates a new tokenizer. * @param tokenizer An Idyl NLP {@link ai.idylnlp.model.nlp.Tokenizer}. * @param toTokenize The string to tokenize. */ public IdylNLPTokenizer(ai.idylnlp.model.nlp.Tokenizer tokenizer, String toTokenize) { tokens = tokenizer.tokenize(toTokenize); } /** * Creates a new tokenizer. * @param tokenizer An Idyl NLP {@link ai.idylnlp.model.nlp.Tokenizer}. * @param preProcessor A token {@link TokenPreProcess preprocessor}. * @param toTokenize The string to tokenize. */ public IdylNLPTokenizer(ai.idylnlp.model.nlp.Tokenizer tokenizer, TokenPreProcess preProcessor, String toTokenize) { this.preProcessor = preProcessor; tokens = tokenizer.tokenize(toTokenize); } @Override public boolean hasMoreTokens() { return (index < tokens.length - 1); } @Override public int countTokens() { return tokens.length; } @Override public String nextToken() { if(index > tokens.length) { throw new IndexOutOfBoundsException("No more tokens."); } if(preProcessor != null) { return preProcessor.preProcess(tokens[index++]); } else { return tokens[index++]; } } @Override public List<String> getTokens() { return Arrays.asList(tokens); } @Override public void setTokenPreProcessor(TokenPreProcess tokenPreProcessor) { this.preProcessor = tokenPreProcessor; } }
0
java-sources/ai/idylnlp/idylnlp-dl4j/1.1.0/ai/idylnlp
java-sources/ai/idylnlp/idylnlp-dl4j/1.1.0/ai/idylnlp/dl4j/IdylNLPTokenizerFactory.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.dl4j; import java.io.InputStream; import org.apache.commons.lang3.NotImplementedException; import org.deeplearning4j.text.tokenization.tokenizer.TokenPreProcess; import org.deeplearning4j.text.tokenization.tokenizer.Tokenizer; import org.deeplearning4j.text.tokenization.tokenizerfactory.TokenizerFactory; /** * Implements {@link TokenizerFactory} to make Idyl NLP's tokenizers * available to DeepLearning4j's NLP capabilities. * * @author Mountain Fog, Inc. * */ public class IdylNLPTokenizerFactory implements TokenizerFactory { private ai.idylnlp.model.nlp.Tokenizer tokenizer; private TokenPreProcess preProcessor; /** * Creates a new tokenizer factory. * @param tokenizer An Idyl NLP {@link ai.idylnlp.model.nlp.Tokenizer}. */ public IdylNLPTokenizerFactory(ai.idylnlp.model.nlp.Tokenizer tokenizer) { this.tokenizer = tokenizer; } /** * Creates a new tokenizer factory. * @param tokenizer An Idyl NLP {@link ai.idylnlp.model.nlp.Tokenizer}. */ public IdylNLPTokenizerFactory(ai.idylnlp.model.nlp.Tokenizer tokenizer, TokenPreProcess preProcessor) { this.tokenizer = tokenizer; this.preProcessor = preProcessor; } @Override public Tokenizer create(String toTokenize) { return new IdylNLPTokenizer(tokenizer, preProcessor, toTokenize); } @Override public Tokenizer create(InputStream toTokenize) { throw new NotImplementedException("Not yet implemented."); } @Override public void setTokenPreProcessor(TokenPreProcess preProcessor) { this.preProcessor = preProcessor; } @Override public TokenPreProcess getTokenPreProcessor() { return preProcessor; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/Constants.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model; /** * Constants utilized by Idyl NLP. * @author Mountain Fog, Inc. */ public class Constants { /** * A constant for UTF-8. */ public static final String ENCODING_UTF8 = "UTF-8"; /** * The default number of folds for cross validation. */ public static final int DEFAULT_NFOLDS = 10; private Constants() { // This is a utility class. } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/ModelManifestCache.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model; import java.util.HashMap; import java.util.Map; import java.util.Set; import com.neovisionaries.i18n.LanguageCode; import ai.idylnlp.model.manifest.StandardModelManifest; /** * Caches model manifests in memory per language and type. * * @author Mountain Fog, Inc. * */ public class ModelManifestCache { private Map<String, Map<LanguageCode, Set<StandardModelManifest>>> cache; public ModelManifestCache() { cache = new HashMap<String, Map<LanguageCode, Set<StandardModelManifest>>>(); } public void add(String type, LanguageCode language, Set<StandardModelManifest> modelManifests) { Map<LanguageCode, Set<StandardModelManifest>> models = new HashMap<>(); models.put(language, modelManifests); cache.put(type, models); } public Set<StandardModelManifest> get(String type, LanguageCode language) { Set<StandardModelManifest> modelManifests = null; Map<LanguageCode, Set<StandardModelManifest>> models = cache.get(type); if(models != null) { modelManifests = models.get(language); } return modelManifests; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/ModelValidator.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model; import ai.idylnlp.model.exceptions.ValidationException; import ai.idylnlp.model.manifest.ModelManifest; public interface ModelValidator { /** * Validates the model against some logic. For example, you may want to validate the * model's version against your current code for compatibility. * @param manifest The {@link ModelManifest} for the model to validate. * @return <code>true</code> if validation is successful. * @throws ValidationException Thrown if the validation cannot make a * determination of valid or not. In this case the validation should * likely be treated as failed. */ boolean validate(ModelManifest manifest) throws ValidationException; }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/Namespaces.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model; public class Namespaces { public static final String MTNFOG = "http://www.mtnfog.com/idyl/1.0/"; public static final String DBPEDIA = "http://dbpedia.org/resource/"; private Namespaces() { // Utility class. } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/entity/Entity.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.entity; import java.io.Serializable; import java.util.HashMap; import java.util.Map; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; /** * An entity. * * @author Mountain Fog, Inc. */ public class Entity implements Serializable { private static final long serialVersionUID = 5297145844547340358L; private String text; private double confidence; private Span span; private String type; private String uri; private String languageCode; private String context; private String documentId; private long extractionDate; private Map<String, String> metadata; /** * Create a new entity. */ public Entity() { this.metadata = new HashMap<String, String>(); } /** * Create a new entity from an existing entity. * @param entity An existing entity. */ public Entity(Entity entity) { setConfidence(entity.getConfidence()); setMetadata(entity.getMetadata()); setType(entity.getType()); setLanguageCode(entity.getLanguageCode()); setSpan(entity.getSpan()); setText(entity.getText()); setUri(entity.getUri()); } /** * Create a new entity given the attributes of the entity. * @param text The text of the entity. * @param confidence The confidence the text as determined during the extraction. This will be a decimal value between 0 and 100. A higher value indicates a higher level of confidence. * @param type The type of entity. * @param languageCode The two-letter ISO language code of the entity. */ public Entity(String text, double confidence, String type, String languageCode) { this.text = text; this.confidence = confidence; this.type = type; this.metadata = new HashMap<String, String>(); this.languageCode = languageCode; } /** * Create a new entity given the attributes of the entity. * @param text The text of the entity. * @param confidence The confidence the text as determined during the extraction. This will be a decimal value between 0 and 100. A higher value indicates a higher level of confidence. * @param span The location of the entity in the text. * @param type The type of entity. * @param languageCode The two-letter ISO language code of the entity. */ public Entity(String text, double confidence, String type, Span span, String languageCode) { this.text = text; this.confidence = confidence; this.span = span; this.type = type; this.metadata = new HashMap<String, String>(); this.languageCode = languageCode; } /** * Create a new entity given the attributes of the entity. * @param text The text of the entity. */ public Entity(String text) { this.text = text; this.metadata = new HashMap<String, String>(); } /** * Create a new entity given the attributes of the entity. * @param text The text of the entity. * @param type The type of entity. */ public Entity(String text, String type) { this.text = text; this.type = type; this.metadata = new HashMap<String, String>(); } /** * {@inheritDoc} */ @Override public int hashCode() { return new HashCodeBuilder(17, 31) .append(text) .append(confidence) .append(span) .append(type) .append(uri) .append(languageCode) .append(context) .append(documentId) .toHashCode(); } /** * {@inheritDoc} */ @Override public boolean equals(Object obj) { if(obj != null && obj instanceof Entity) { final Entity other = (Entity) obj; return new EqualsBuilder() .append(text, other.text) .append(confidence, other.confidence) .append(span, other.span) .append(type, other.type) .append(uri, other.uri) .append(languageCode, other.languageCode) .append(context, other.context) .append(documentId, other.documentId) .isEquals(); } return false; } /** * {@inheritDoc} */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Text: " + text + "; "); sb.append("Confidence: " + confidence + "; "); sb.append("Type: " + type + "; "); sb.append("Language Code: " + languageCode + "; "); if(span != null) { sb.append("Span: " + span.toString() + "; "); } return sb.toString(); } /** * Gets the text of the entity. * @return The text of the entity. */ public String getText() { return text; } /** * Sets the text of the entity. * @param text The text of the entity. */ public void setText(String text) { this.text = text; } /** * Gets the confidence the entity actually is an entity. * @return The confidence the entity is actually an entity. This will be a value between 0 and 100. */ public double getConfidence() { return confidence; } /** * Sets the confidence the entity actually is an entity. * @param confidence The confidence of the entity. This should be a value between 0 and 100. */ public void setConfidence(double confidence) { this.confidence = confidence; } /** * Gets the URI of the entity. * @return The entity URI. */ public String getUri() { return uri; } /** * Sets the URI of the entity. * @param uri The entity URI. */ public void setUri(String uri) { this.uri = uri; } /** * Gets the entity {@link Span} in the text. * @return The entity {@link Span} in the text. */ public Span getSpan() { return span; } /** * Sets the entity {@link Span} in the text. * @param span The entity {@link Span} in the text. */ public void setSpan(Span span) { this.span = span; } /** * Gets the language code of the entity. * @return The language code. */ public String getLanguageCode() { return languageCode; } /** * Sets the language code for the entity. * @param languageCode The language code. */ public void setLanguageCode(String languageCode) { this.languageCode = languageCode; } /** * Gets the type of the entity. * @return The type of the entity. */ public String getType() { return type; } /** * Sets the type of the entity. * @param type The type of the entity. */ public void setType(String type) { this.type = type; } /** * Gets the context of the entity. * @return The context of the entity. */ public String getContext() { return context; } /** * Sets the context of the entity. * @param context The context of the entity. */ public void setContext(String context) { this.context = context; } /** * Gets the document ID of the entity. * @return The document ID. */ public String getDocumentId() { return documentId; } /** * Sets the document ID of the entity. * @param documentId The document ID. */ public void setDocumentId(String documentId) { this.documentId = documentId; } /** * Gets the extraction date. * @return The extraction date. */ public long getExtractionDate() { return extractionDate; } /** * Sets the extraction date. * @param extractionDate The extraction date. */ public void setExtractionDate(long extractionDate) { this.extractionDate = extractionDate; } /** * Gets the entity metadata. * @return The entity metadata. */ public Map<String, String> getMetadata() { return metadata; } /** * Sets the entity metadata. * @param metadata The entity metadata. */ public void setMetadata(Map<String, String> metadata) { this.metadata = metadata; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/entity/EntityMetadata.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.entity; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; import org.apache.commons.collections4.CollectionUtils; public class EntityMetadata { private String name; private String value; /** * Converts a list of {@link EntityMetadata} to a map. * @param metadata A list of {@link EntityMetadata}. * @return A map that contains the entity metadata. */ public static Map<String, String> toMap(List<EntityMetadata> metadata) { Map<String, String> map = new LinkedHashMap<String, String>(); if(CollectionUtils.isNotEmpty(metadata)) { for(EntityMetadata m : metadata) { map.put(m.getName(), m.getValue()); } } return map; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getValue() { return value; } public void setValue(String value) { this.value = value; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/entity/Span.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.entity; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; /** * A span in text identified by token and character indexes. * * @author Mountain Fog, Inc. * */ public class Span { private int tokenStart; private int tokenEnd; /** * Creates a new span. * @param tokenStart The position of the start of the token's span. * */ public Span(int tokenStart, int tokenEnd) { this.tokenStart = tokenStart; this.tokenEnd = tokenEnd; } /** * Returns the token-based span as a formatted string. * An example is: [3..5) */ @Override public String toString() { return "[" + tokenStart + ".." + tokenEnd + ")"; } /** * {@inheritDoc} */ @Override public int hashCode() { return new HashCodeBuilder(17, 31) .append(tokenStart) .append(tokenEnd) .toHashCode(); } /** * {@inheritDoc} */ @Override public boolean equals(Object obj) { if(obj != null && obj instanceof Span) { final Span other = (Span) obj; return new EqualsBuilder() .append(tokenStart, other.tokenStart) .append(tokenEnd, other.tokenEnd) .isEquals(); } return false; } /** * Gets the token's start of the span. * @return The token's start of the span. */ public int getTokenStart() { return tokenStart; } /** * Gets the end of the span. * @return The end of the span. */ public int getTokenEnd() { return tokenEnd; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/entity
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/entity/comparators/EntityComparator.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.entity.comparators; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import ai.idylnlp.model.entity.Entity; /** * {@link Comparator Comparator} for {@link Entity entities}. * Supports sorting by entity confidence and entity text. * * @author Mountain Fog, Inc. * */ public class EntityComparator implements Comparator<Entity> { private Order sortingBy; /** * Creates a new {@link EntityComparator} with the given * sorting method. * @param sortingBy The {@link Order} to sort the entities. */ public EntityComparator(Order sortingBy) { this.sortingBy = sortingBy; } public enum Order { CONFIDENCE, TEXT } @Override public int compare(Entity entity1, Entity entity2) { switch (sortingBy) { case CONFIDENCE: return Double.compare(entity1.getConfidence(), entity2.getConfidence()); case TEXT: return entity1.getText().compareTo(entity2.getText()); } throw new IllegalArgumentException("Invalid sort type."); } /** * Gets the sorting order. * @return The {@link Order}. */ public Order getSortingBy() { return sortingBy; } /** * Sort the entities. * @param entities The set of {@link Entity entities}. * @param sortingBy The sorting method. * @return A set of sorted {@link Entity entities}. */ public static Set<Entity> sort(Set<Entity> entities, Order sortingBy) { EntityComparator comparator = new EntityComparator(sortingBy); List<Entity> list = new ArrayList<Entity>(entities); Collections.sort(list, comparator); Set<Entity> sortedEntities = new LinkedHashSet<>(list); return sortedEntities; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/exceptions/EntityFinderException.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.exceptions; /** * This exception is thrown when entity extraction fails. * * @author Mountain Fog, Inc. * */ public class EntityFinderException extends Exception { private static final long serialVersionUID = -4170124556878454011L; /** * Creates a new exception. * @param message The message of the exception. * @param ex The underlying exception. */ public EntityFinderException(String message, Exception ex) { super(message, ex); } /** * Creates a new exception. * @param message The message of the exception. */ public EntityFinderException(String message) { super(message); } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/exceptions/ExtractorException.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.exceptions; /** * An exception that is thrown if an error is encountered * during text extraction from a document. * * @author Mountain Fog, Inc. * */ public class ExtractorException extends Exception { private static final long serialVersionUID = 2325000410259951206L; /** * Creates a new exception. * @param message The message of the exception. */ public ExtractorException(String message) { super(message); } /** * Creates a new exception. * @param message The message of the exception. * @param throwable The exception. */ public ExtractorException(String message, Throwable throwable) { super(message, throwable); } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/exceptions/ModelLoaderException.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.exceptions; /** * This exception is thrown when the loading of a model * fails. * * @author Mountain Fog, Inc. * */ public class ModelLoaderException extends Exception { private static final long serialVersionUID = -4170124556878454011L; /** * Creates a new exception. * @param message The message of the exception. * @param ex The underlying exception. */ public ModelLoaderException(String message, Exception ex) { super(message, ex); } /** * Creates a new exception. * @param message The message of the exception. */ public ModelLoaderException(String message) { super(message); } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/exceptions/ValidationException.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.exceptions; /** * This exception is thrown if a license does not validate. * @author Mountain Fog, Inc. */ public class ValidationException extends Exception { private static final long serialVersionUID = 5161843297983375847L; /** * Creates a new exception. * @param message The message of the exception. */ public ValidationException(String message) { super(message); } /** * Creates a new exception. * @param message The message of the exception. * @param ex The exception. */ public ValidationException(String message, Exception ex) { super(message, ex); } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/language/Language.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.language; import com.neovisionaries.i18n.LanguageCode; public class Language { private Language() { // Utility class. } /** * Determines if a string is a valid language code. * @param languageCode A language code. * @return <code>true</code> if the string is a valid 3-letter language code; * otherwise <code>false</code>. */ public static boolean validate(String languageCode) { LanguageCode code = LanguageCode.getByCodeIgnoreCase(languageCode); if(code == null) { return false; } else { return true; } } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/manifest/DocumentModelManifest.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.manifest; import java.util.List; import java.util.Properties; import com.neovisionaries.i18n.LanguageCode; public class DocumentModelManifest extends ModelManifest { public static final String TYPE = "document"; private List<String> labels; // TODO: Change to a builder pattern like StandardModelManifest. public DocumentModelManifest(String modelId, String modelFileName, LanguageCode languageCode, String type, String name, String creatorVersion, String source, List<String> labels, Properties properties) { super(modelId, modelFileName, languageCode, type, name, creatorVersion, source, ModelManifest.SECOND_GENERATION, properties); this.labels = labels; } public List<String> getLabels() { return labels; } public LanguageCode getLanguageCode() { return languageCode; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/manifest/ModelManifest.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.manifest; import java.util.Properties; import com.neovisionaries.i18n.LanguageCode; /** * An abstract model manifest. * * @author Mountain Fog, Inc. * */ public abstract class ModelManifest { /** * First generation MaxEnt model. */ public static final int FIRST_GENERATION = 1; /** * Second generation deep learning model. */ public static final int SECOND_GENERATION = 2; protected String modelId; protected String name; protected String modelFileName; protected LanguageCode languageCode; protected String type; protected String creatorVersion; protected String source; protected Properties properties; // The "generation" property of the manifest allows // us to tell the generation of the model that the // manifest describes. protected int generation; protected ModelManifest(String modelId, String modelFileName, LanguageCode languageCode, String type, String name, String creatorVersion, String source, int generation, Properties properties) { this.modelId = modelId; this.modelFileName = modelFileName; this.languageCode = languageCode; this.type = type; this.name = name; this.creatorVersion = creatorVersion; this.source = source; this.generation = generation; this.properties = properties; } public String getModelId() { return modelId; } public String getName() { return name; } public String getModelFileName() { return modelFileName; } public LanguageCode getLanguageCode() { return languageCode; } public String getType() { return type; } public String getCreatorVersion() { return creatorVersion; } public int getGeneration() { return generation; } public String getSource() { return source; } public Properties getProperties() { return properties; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/manifest/ModelManifestUtils.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.manifest; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.Properties; import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import com.neovisionaries.i18n.LanguageCode; /** * Utility methods for working with model manifest files. * * @author Mountain Fog, Inc. * */ public class ModelManifestUtils { private static final Logger LOGGER = LogManager.getLogger(ModelManifestUtils.class); public static final String MANIFEST_MODEL_ID = "model.id"; public static final String MANIFEST_MODEL_NAME = "model.name"; public static final String MANIFEST_MODEL_TYPE = "model.type"; public static final String MANIFEST_MODEL_SUBTYPE = "model.subtype"; public static final String MANIFEST_MODEL_FILENAME = "model.filename"; public static final String MANIFEST_LANGUAGE_CODE = "language.code"; public static final String MANIFEST_ENCRYPTION_KEY = "encryption.key"; public static final String MANIFEST_CREATOR_VERSION = "creator.version"; public static final String MANIFEST_MODEL_SOURCE = "model.source"; public static final String MANIFEST_VECTORS_SOURCE = "vectors.source"; public static final String MANIFEST_BEAM_SIZE = "beam.size"; public static final String MANIFEST_GENERATION = "generation"; // Used for second generation NER model manifests. public static final String MANIFEST_VECTORS_FILENAME = "vectors.file"; public static final String MANIFEST_WINDOW_SIZE = "window.size"; /** * Generates a model manifest file. If the manifest file already exists it will be overwritten. * @param manifestFile The {@link File} to write. * @param modelManifest The {@link StandardModelManifest}. * @throws IOException Thrown if an existing file cannot be deleted or if the manifest file cannot be written. */ public static void generateStandardModelManifest(StandardModelManifest modelManifest, File manifestFile) throws IOException { // If the manifest file already exists delete it. if(manifestFile.exists()) { LOGGER.info("Removing existing manifest file {}.", manifestFile.getAbsolutePath()); manifestFile.delete(); } List<String> lines = new LinkedList<String>(); lines.add(MANIFEST_MODEL_ID + "=" + modelManifest.getModelId()); lines.add(MANIFEST_MODEL_NAME + "=" + modelManifest.getName()); lines.add(MANIFEST_MODEL_TYPE + "=" + modelManifest.getType().toLowerCase()); lines.add(MANIFEST_MODEL_SUBTYPE + "=" + modelManifest.getSubtype().toLowerCase()); lines.add(MANIFEST_MODEL_FILENAME + "=" + modelManifest.getModelFileName()); lines.add(MANIFEST_LANGUAGE_CODE + "=" + modelManifest.getLanguageCode()); lines.add(MANIFEST_ENCRYPTION_KEY + "=" + modelManifest.getEncryptionKey()); lines.add(MANIFEST_CREATOR_VERSION + "=" + modelManifest.getCreatorVersion()); lines.add(MANIFEST_MODEL_SOURCE + "=" + modelManifest.getSource()); lines.add(MANIFEST_GENERATION + "=" + 1); // Only write the beam size to the manifest if it is not the default. if(modelManifest.getBeamSize() != StandardModelManifest.DEFAULT_BEAM_SIZE) { lines.add(MANIFEST_BEAM_SIZE + "=" + modelManifest.getBeamSize()); } FileUtils.writeLines(manifestFile, lines); } /** * Generates a model manifest file. If the manifest file already exists it will be overwritten. * This function is used by the user-generated models tool. * @param manifestFile The {@link File} to write. * @param modelId The model ID. * @param name The name of the model. This is not a file name. * @param type The entity class or "sentence" or "token". * @param subtype The model subtype (dictionary). * @param modelFile The filename of the model without any path. * @param languageCode The {@link LanguageCode}. * @param encryptionKey The model's encryption key. * @param creatorVersion The version of the implementing application. * @param source A URL where the model can be downloaded. * @throws IOException Thrown if an existing file cannot be deleted or if the manifest file cannot be written. */ public static void generateStandardModelManifest(File manifestFile, String modelId, String name, String type, String subtype, String modelFile, LanguageCode languageCode, String encryptionKey, String creatorVersion, String source) throws IOException { // If the manifest file already exists delete it. if(manifestFile.exists()) { LOGGER.info("Removing existing manifest file {}.", manifestFile.getAbsolutePath()); manifestFile.delete(); } List<String> lines = new LinkedList<String>(); lines.add(MANIFEST_MODEL_ID + "=" + modelId); lines.add(MANIFEST_MODEL_NAME + "=" + name); lines.add(MANIFEST_MODEL_TYPE + "=" + type.toLowerCase()); lines.add(MANIFEST_MODEL_SUBTYPE + "=" + subtype.toLowerCase()); lines.add(MANIFEST_MODEL_FILENAME + "=" + modelFile); lines.add(MANIFEST_LANGUAGE_CODE + "=" + languageCode.getAlpha3().toString().toLowerCase()); lines.add(MANIFEST_ENCRYPTION_KEY + "=" + encryptionKey); lines.add(MANIFEST_CREATOR_VERSION + "=" + creatorVersion); lines.add(MANIFEST_MODEL_SOURCE + "=" + source); lines.add(MANIFEST_GENERATION + "=" + ModelManifest.FIRST_GENERATION); // The beam size is assumed to be the default so it is not written to the manifest. FileUtils.writeLines(manifestFile, lines); } /** * Generates a model manifest for a second generation model. * @param manifestFile The {@link File} to write. * @param modelManifest The {@link SecondGenModelManifest manifest} to write. * @throws IOException Thrown if an existing file cannot be deleted or if the manifest file cannot be written. */ public static void generateSecondGenModelManifest(File manifestFile, SecondGenModelManifest modelManifest) throws IOException { // If the manifest file already exists delete it. if(manifestFile.exists()) { LOGGER.info("Removing existing manifest file {}.", manifestFile.getAbsolutePath()); manifestFile.delete(); } List<String> lines = new LinkedList<String>(); lines.add(MANIFEST_MODEL_ID + "=" + modelManifest.getModelId()); lines.add(MANIFEST_MODEL_FILENAME + "=" + modelManifest.getModelFileName()); lines.add(MANIFEST_MODEL_NAME + "=" + modelManifest.getName()); lines.add(MANIFEST_MODEL_TYPE + "=" + modelManifest.getType().toLowerCase()); lines.add(MANIFEST_LANGUAGE_CODE + "=" + modelManifest.getLanguageCode()); lines.add(MANIFEST_CREATOR_VERSION + "=" + modelManifest.getCreatorVersion()); lines.add(MANIFEST_VECTORS_FILENAME + "=" + modelManifest.getVectorsFileName()); lines.add(MANIFEST_WINDOW_SIZE + "=" + modelManifest.getWindowSize()); lines.add(MANIFEST_MODEL_SOURCE + "=" + modelManifest.getSource()); lines.add(MANIFEST_VECTORS_SOURCE + "=" + modelManifest.getVectorsSource()); lines.add(MANIFEST_GENERATION + "=" + ModelManifest.SECOND_GENERATION); FileUtils.writeLines(manifestFile, lines); } /** * Get the {@link ModelManifest manifests} for NER models. * @param modelsDirectory The directory containing the model manifests. * @param type The type of model manifests to look for. * @return A list of {@link StandardModelManifest manifests}. */ public static List<ModelManifest> getModelManifests(String modelsDirectory, String type) { final List<ModelManifest> modelManifests = new LinkedList<ModelManifest>(); final String[] extensions = {"manifest"}; final File file = new File(modelsDirectory); if(!file.exists() || !file.isDirectory()) { LOGGER.warn("Model directory {} is not a valid directory.", modelsDirectory); return Collections.emptyList(); } final Collection<File> modelManifestFiles = FileUtils.listFiles(file, extensions, true); for(File modelManifestFile : modelManifestFiles) { final String fullManifestPath = modelsDirectory + File.separator + modelManifestFile.getName(); LOGGER.info("Found model manifest {}.", fullManifestPath); try { final ModelManifest modelManifest = readManifest(fullManifestPath); if(modelManifest != null) { // Return all models or only return certain types. if(StringUtils.isEmpty(type) || StringUtils.equalsIgnoreCase(type, modelManifest.getType())) { LOGGER.info("Entity Class: {}, Model File Name: {}, Language Code: {}", modelManifest.getType(), modelManifest.getModelFileName(), modelManifest.getLanguageCode()); modelManifests.add(modelManifest); } } } catch (Exception ex) { LOGGER.error("Unable to read model manifest: " + fullManifestPath, ex); } } return modelManifests; } /** * Get the {@link ModelManifest manifests} for NER models. * @param modelsDirectory The directory containing the model manifests. * @return A list of {@link StandardModelManifest manifests}. */ public static List<ModelManifest> getModelManifests(String modelsDirectory) { return getModelManifests(modelsDirectory, null); } /** * Reads a model manifest. * @param fullManifestPath The full path to the model manifest. * @return A {@link StandardModelManifest manifest}, or <code>null</code> if the * model manifest is not properly configured or is not a NER model manifest. * @throws Exception Thrown if the model manifest cannot be read. */ public static ModelManifest readManifest(String fullManifestPath) throws Exception { LOGGER.info("Validating model manifest {}.", fullManifestPath); final InputStream inputStream = new FileInputStream(fullManifestPath); final Properties properties = new Properties(); properties.load(inputStream); // Get the model generation from the manifest. int generation = Integer.valueOf(properties.getProperty(MANIFEST_GENERATION, String.valueOf(ModelManifest.FIRST_GENERATION))); // Get properties common to all generations. String modelId = properties.getProperty(MANIFEST_MODEL_ID); String name = properties.getProperty(MANIFEST_MODEL_NAME); String modelFileName = properties.getProperty(MANIFEST_MODEL_FILENAME); String languageCode = properties.getProperty(MANIFEST_LANGUAGE_CODE); String modelType = properties.getProperty(MANIFEST_MODEL_TYPE); String creatorVersion = properties.getProperty(MANIFEST_CREATOR_VERSION); String source = properties.getProperty(MANIFEST_MODEL_SOURCE); // Validate the property values. if(StringUtils.isEmpty(modelId)) { LOGGER.warn("The model.id in {} is missing.", fullManifestPath); return null; } if(StringUtils.isEmpty(modelType)) { LOGGER.warn("The model.type in {} is missing.", fullManifestPath); return null; } if(StringUtils.isEmpty(modelFileName)) { LOGGER.warn("The model.filename in {} is missing.", fullManifestPath); return null; } if(StringUtils.isEmpty(languageCode)) { LOGGER.warn("The language.code in {} is missing.", fullManifestPath); return null; } if(StringUtils.isEmpty(creatorVersion)) { LOGGER.warn("The creator.version in {} is missing.", fullManifestPath); // No reason to stop model loading here. } if(StringUtils.isEmpty(name)) { // If there is no name just use the modelId as the name. name = modelId; } // Get the LanguageCode for the language. final LanguageCode code = LanguageCode.getByCodeIgnoreCase(languageCode); if(generation == ModelManifest.FIRST_GENERATION) { // Read the contents of the manifest. final String modelSubtype = properties.getProperty(MANIFEST_MODEL_SUBTYPE, StandardModelManifest.DEFAULT_SUBTYPE); final String encryptionKey = properties.getProperty(MANIFEST_ENCRYPTION_KEY); int beamSize = Integer.valueOf(properties.getProperty(MANIFEST_BEAM_SIZE, String.valueOf(StandardModelManifest.DEFAULT_BEAM_SIZE))); inputStream.close(); if(!StringUtils.isEmpty(modelType)) { modelType = modelType.toLowerCase(); } // Validate properties specific to a standard model manifest. // All properties except encryption.key are required. Make sure each one is present. if(beamSize <= 0) { LOGGER.warn("The beam size value of {} in {} is invalid.", beamSize, fullManifestPath); return null; } return new StandardModelManifest.ModelManifestBuilder(modelId, name, modelFileName, code, encryptionKey, modelType, modelSubtype, creatorVersion, source, beamSize, properties).build(); } else if(generation == ModelManifest.SECOND_GENERATION) { // Is it a document model? if(StringUtils.equalsIgnoreCase(modelType, DocumentModelManifest.TYPE)) { final String modelSubtype = properties.getProperty(MANIFEST_MODEL_SUBTYPE, StandardModelManifest.DEFAULT_SUBTYPE); final List<String> labels = Arrays.asList(modelSubtype.split(",")); return new DocumentModelManifest(modelId, modelFileName, code, modelType, name, creatorVersion, source, labels, properties); } else { final String vectorsFile = properties.getProperty(MANIFEST_VECTORS_FILENAME); final String vectorsSource = properties.getProperty(MANIFEST_VECTORS_SOURCE); final int windowSize = Integer.valueOf(properties.getProperty(MANIFEST_WINDOW_SIZE, "5")); LOGGER.info("Initializing second generation model manifest with widow size of {}.", windowSize); // Validate properties specific to a second generation model manifest. if(StringUtils.isEmpty(vectorsFile)) { LOGGER.warn("The vectors.file in {} is invalid.", fullManifestPath); return null; } return new SecondGenModelManifest(modelId, modelFileName, code, modelType, name, creatorVersion, vectorsFile, windowSize, source, vectorsSource, properties); } } else { throw new IllegalArgumentException("Invalid model generation value of: " + generation); } } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/manifest/SecondGenModelManifest.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.manifest; import java.util.Properties; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import com.neovisionaries.i18n.LanguageCode; /** * A model manifest for a second generation (deep learning) model. * * @author Mountain Fog, Inc. * */ public class SecondGenModelManifest extends ModelManifest implements Comparable<SecondGenModelManifest> { public static final String ENTITY = "entity"; private String vectorsFileName; private int windowSize; private String vectorsSource; public SecondGenModelManifest(String modelId, String modelFileName, LanguageCode languageCode, String type, String name, String creatorVersion, String vectorsFileName, int windowSize, String source, String vectorsSource, Properties properties) { super(modelId, modelFileName, languageCode, type, name, creatorVersion, source, ModelManifest.SECOND_GENERATION, properties); this.vectorsFileName = vectorsFileName; this.windowSize = windowSize; this.vectorsSource = vectorsSource; } @Override public final int hashCode() { return new HashCodeBuilder(17, 31) .append(modelId) .append(modelFileName) .append(vectorsFileName) .append(windowSize) .append(name) .append(languageCode) .append(type) .append(creatorVersion) .append(source) .append(vectorsSource) .append(generation) .toHashCode(); } @Override public final boolean equals(Object obj) { if(obj instanceof SecondGenModelManifest){ final SecondGenModelManifest other = (SecondGenModelManifest) obj; return new EqualsBuilder() .append(modelId, other.getModelId()) .append(modelFileName, other.getModelFileName()) .append(name, other.getName()) .append(vectorsFileName, other.getVectorsFileName()) .append(windowSize, windowSize) .append(languageCode, other.getLanguageCode()) .append(type, other.getType()) .append(creatorVersion, other.getCreatorVersion()) .append(source, other.getSource()) .append(vectorsSource, other.getVectorsSource()) .append(generation, other.getGeneration()) .isEquals(); } else { return false; } } @Override public int compareTo(SecondGenModelManifest modelManifest) { return modelManifest.getType().compareTo(type); } public String getVectorsFileName() { return vectorsFileName; } public int getWindowSize() { return windowSize; } public String getVectorsSource() { return vectorsSource; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/manifest/StandardModelManifest.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.manifest; import java.util.Properties; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import com.neovisionaries.i18n.LanguageCode; /** * A model manifest. * * @author Mountain Fog, Inc. * */ public class StandardModelManifest extends ModelManifest implements Comparable<StandardModelManifest> { // The beam size controls the depth of the beam search in OpenNLP's context evaluation. public static final int DEFAULT_BEAM_SIZE = 3; public static final String DEFAULT_SUBTYPE = "none"; public static final String DICTIONARY_SUBTYPE = "dictionary"; public static final String ENTITY = "entity"; public static final String SENTENCE = "sentence"; public static final String TOKEN = "token"; public static final String POS = "pos"; public static final String LEMMA = "lemma"; protected String encryptionKey = StringUtils.EMPTY; protected String subtype = DEFAULT_SUBTYPE; protected int beamSize = DEFAULT_BEAM_SIZE; public static class ModelManifestBuilder { private String modelId; private String name; private String modelFileName; private LanguageCode languageCode; private String encryptionKey; private String type; private String subtype; private String creatorVersion; private String source; private int beamSize = DEFAULT_BEAM_SIZE; private Properties properties; public ModelManifestBuilder() { } public ModelManifestBuilder(String modelId, String name, String modelFileName, LanguageCode languageCode, String encryptionKey, String type, String subtype, String creatorVersion, String source, int beamSize, Properties properties) { // TODO: Make sure none of these values are null. this.modelId = modelId; this.name = name; this.modelFileName = modelFileName; this.languageCode = languageCode; this.encryptionKey = encryptionKey; this.type = type; this.subtype = subtype; this.creatorVersion = creatorVersion; this.source = source; this.beamSize = beamSize; this.properties = properties; } public ModelManifestBuilder(String modelId, String name, String modelFileName, LanguageCode languageCode, String encryptionKey, String type, String subtype, String creatorVersion, String source, Properties properties) { // TODO: Make sure none of these values are null. this.modelId = modelId; this.name = name; this.modelFileName = modelFileName; this.languageCode = languageCode; this.encryptionKey = encryptionKey; this.type = type; this.subtype = subtype; this.creatorVersion = creatorVersion; this.source = source; this.properties = properties; } public ModelManifestBuilder(String modelId, String name, String modelFileName, LanguageCode languageCode, String encryptionKey, String type, String creatorVersion, String source, Properties properties) { // TODO: Make sure none of these values are null. this.modelId = modelId; this.name = name; this.modelFileName = modelFileName; this.languageCode = languageCode; this.encryptionKey = encryptionKey; this.type = type; this.subtype = DEFAULT_SUBTYPE; this.creatorVersion = creatorVersion; this.source = source; this.properties = properties; } public void setModelId(String modelId) { this.modelId = modelId; } public void setName(String name) { this.name = name; } public void setModelFileName(String modelFileName) { this.modelFileName = modelFileName; } public void setLanguageCode(LanguageCode languageCode) { this.languageCode = languageCode; } public void setEncryptionKey(String encryptionKey) { this.encryptionKey = encryptionKey; } public void setType(String type) { this.type = type; } public void setSubtype(String subtype) { this.subtype = subtype; } public void setCreatorVersion(String creatorVersion) { this.creatorVersion = creatorVersion; } public void setSource(String source) { this.source = source; } public void setBeamSize(int beamSize) { this.beamSize = beamSize; } public Properties getProperties() { return properties; } public void setProperties(Properties properties) { this.properties = properties; } public StandardModelManifest build() { return new StandardModelManifest(modelId, modelFileName, languageCode, encryptionKey, type, subtype, name, creatorVersion, source, beamSize, properties); } } private StandardModelManifest(String modelId, String modelFileName, LanguageCode languageCode, String encryptionKey, String type, String subtype, String name, String creatorVersion, String source, int beamSize, Properties properties) { super(modelId, modelFileName, languageCode, type, name, creatorVersion, source, ModelManifest.FIRST_GENERATION, properties); this.encryptionKey = encryptionKey; this.subtype = subtype; this.beamSize = beamSize; this.properties = properties; } @Override public final int hashCode() { return new HashCodeBuilder(17, 31) .append(modelId) .append(modelFileName) .append(name) .append(encryptionKey) .append(languageCode) .append(type) .append(subtype) .append(creatorVersion) .append(source) .append(beamSize) .append(generation) .toHashCode(); } @Override public final boolean equals(Object obj) { if(obj instanceof StandardModelManifest){ final StandardModelManifest other = (StandardModelManifest) obj; return new EqualsBuilder() .append(modelId, other.getModelId()) .append(modelFileName, other.getModelFileName()) .append(name, other.getName()) .append(encryptionKey, other.getEncryptionKey()) .append(languageCode, other.getLanguageCode()) .append(type, other.getType()) .append(subtype, other.getSubtype()) .append(creatorVersion, other.getCreatorVersion()) .append(source, other.getSource()) .append(beamSize, other.getBeamSize()) .append(generation, other.getGeneration()) .isEquals(); } else { return false; } } @Override public int compareTo(StandardModelManifest modelManifest) { return modelManifest.getType().compareTo(type); } public String getModelId() { return modelId; } public String getName() { return name; } public String getModelFileName() { return modelFileName; } public LanguageCode getLanguageCode() { return languageCode; } public String getEncryptionKey() { return encryptionKey; } public String getType() { return type; } public String getSubtype() { return subtype; } public String getCreatorVersion() { return creatorVersion; } public int getBeamSize() { return beamSize; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/AnnotationWriter.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp; import java.util.Collection; import ai.idylnlp.model.entity.Entity; /** * Interface for writing annotated input text. The annotated * text can be written anywhere, such as a simple text file, * a database, or memory. * * @author Mountain Fog, Inc. * */ @FunctionalInterface public interface AnnotationWriter { /** * Annotate the entities in the text. * @param entities The set of {@link Entity entities}. * @param text The text containing the entities. * @return Text containing the annotated entities. */ public String annotateText(Collection<Entity> entities, String text); }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/ConfidenceFilter.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp; /** * Interface for confidence filters. * * @author Mountain Fog, Inc. * */ public interface ConfidenceFilter { /** * Test the entity's confidence. * @param modelId The ID of the model that extracted the entity. * @param entityConfidence The entity's confidence. * @param confidenceThreshold The confidence threshold. * @return <code>true</code> if the entity should not be filtered out; otherwise <code>false</code>. */ public boolean test(String modelId, double entityConfidence, double confidenceThreshold); /** * Serialize the confidence values. * @return The number of entries serialized. * @throws Exception Thrown if the serialization fails. */ public int serialize() throws Exception; /** * Deserialize the confidence values. * @return The number of entries deserialized. * @throws Exception Thrown if the deserialization fails. */ public int deserialize() throws Exception; /** * Resets all stored confidence values. */ public void resetAll(); /** * Resets all stored confidence values for a single model. * @param modelId The model for which to reset values. */ public void reset(String modelId); /** * Gets if the values are dirty. * @return <code>true</code> if the values are dirty. */ public boolean isDirty(); }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/ConfidenceFilterSerializer.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp; import java.util.Map; import org.apache.commons.math3.stat.descriptive.SynchronizedSummaryStatistics; /** * Interface for confidence filter serializers. * * @author Mountain Fog, Inc. * */ public interface ConfidenceFilterSerializer { /** * Serialize the confidence values. * @param statistics The statistics to serialize. * @throws Exception Thrown if the values cannot be serialized. */ public int serialize(Map<String, SynchronizedSummaryStatistics> statistics) throws Exception; /** * Deserialize the confidence values. * @param statistics The statistics to deserialize. * @return The count of items deserialized. * @throws Exception Thrown if the values cannot be deserialized. */ public int deserialize(Map<String, SynchronizedSummaryStatistics> statistics) throws Exception; }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/DuplicateEntityStrategy.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp; /** * Determines how entities having the same text are handled. * @author Mountain Fog, Inc. * */ public enum DuplicateEntityStrategy { /** * Return all entities - do not remove any. */ RETAIN_DUPICATES, /** * If multiple entities having the same text are extracted * use only the entity with the highest confidence. */ USE_HIGHEST_CONFIDENCE; }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/EntityComparator.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.LinkedHashSet; import java.util.List; import java.util.Set; import ai.idylnlp.model.entity.Entity; /** * {@link Comparator Comparator} for {@link Entity entities}. * Supports sorting by entity confidence and entity text. * * @author Mountain Fog, Inc. * */ public class EntityComparator implements Comparator<Entity> { private EntityOrder sortingBy; /** * Creates a new {@link EntityComparator} with the given * sorting method. * @param sortingBy The {@link EntityOrder} to sort the entities. */ public EntityComparator(EntityOrder sortingBy) { this.sortingBy = sortingBy; } @Override public int compare(Entity entity1, Entity entity2) { switch (sortingBy) { case CONFIDENCE: return Double.compare(entity1.getConfidence(), entity2.getConfidence()); case TEXT: return entity1.getText().compareTo(entity2.getText()); case OCCURRENCE: return Integer.compare(entity1.getSpan().getTokenStart(), entity2.getSpan().getTokenStart()); } throw new IllegalArgumentException("Invalid sort type."); } /** * Gets the sorting order. * @return The {@link EntityOrder}. */ public EntityOrder getSortingBy() { return sortingBy; } /** * Sort the entities. * @param entities The set of {@link Entity entities}. * @param sortingBy The sorting method. * @return A set of sorted {@link Entity entities}. */ public static Set<Entity> sort(Set<Entity> entities, EntityOrder sortingBy) { EntityComparator comparator = new EntityComparator(sortingBy); List<Entity> list = new ArrayList<Entity>(entities); Collections.sort(list, comparator); Set<Entity> sortedEntities = new LinkedHashSet<>(list); return sortedEntities; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/EntityOrder.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp; import java.util.LinkedList; import java.util.List; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; /** * Entity sort orders. * * @author Mountain Fog, Inc. * */ public enum EntityOrder { CONFIDENCE("confidence"), TEXT("text"), OCCURRENCE("occurrence"); private static final Logger LOGGER = LogManager.getLogger(EntityOrder.class); private String order; private EntityOrder(String order) { this.order = order; } /** * Gets an {@link EntityOrder} by value. * @param order The sort order. * @return An {@link EntityOrder}. */ public static EntityOrder fromValue(String order) { if(order.equalsIgnoreCase("confidence")) { return CONFIDENCE; } else if(order.equalsIgnoreCase("text")) { return TEXT; } else if(order.equalsIgnoreCase("occurrence")) { return OCCURRENCE; } // Default to confidence when it is an invalid order. LOGGER.warn("No entity sort order for {}. Entities will be sorted by confidence.", order); return CONFIDENCE; } /** * Gets the allowed sort orders. * @return A list of allowed sort orders. */ public static List<String> getOrders() { List<String> orders = new LinkedList<String>(); for(EntityOrder order : EntityOrder.values()) { orders.add(order.toString()); } return orders; } @Override public String toString() { return order; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/EntitySanitizer.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp; import java.util.Set; import ai.idylnlp.model.entity.Entity; @FunctionalInterface public interface EntitySanitizer { public Set<Entity> sanitizeEntities(Set<Entity> entities); }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/Location.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp; import ai.idylnlp.model.nlp.ner.EntityExtractionRequest; /** * A geographic location. Used by {@link EntityExtractionRequest} * to add location to extracted entities. * * @author Mountain Fog, Inc. * */ public class Location { private double latitude; private double longitude; /** * Creates a new location. * @param latitude The location's latitude. * @param longitude THe location's longitude. */ public Location(double latitude, double longitude) { this.latitude = latitude; this.longitude = longitude; } /** * Gets the location's latitude. * @return The location's latitude. */ public double getLatitude() { return latitude; } /** * Gets the location's longitude. * @return The location's longitude. */ public double getLongitude() { return longitude; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/SentenceDetector.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp; import java.util.List; public interface SentenceDetector { /** * Gets the ISO 639-2 language codes supported by this tokenizer. * @return A list of ISO 639-2 language codes supported by the tokenizer, * or an empty list if the tokenizer is not language-dependent. */ List<String> getLanguageCodes(); /** * Sentence detect a string. * * @param s The string to be sentence detected. * @return The String[] with the individual sentences as the array * elements. */ public String[] sentDetect(String s); /** * Sentence detect a string. * * @param s The string to be sentence detected. * * @return The Span[] with the spans (offsets into s) for each * detected sentence as the individuals array elements. */ public Span[] sentPosDetect(String s); }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/SentenceSanitizer.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp; @FunctionalInterface public interface SentenceSanitizer { public String sanitize(String sentence); }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/Span.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp; public class Span { private int start; private int end; private double prob = 0; private String type; /** * Initializes a new Span Object. Sets the prob to 0 as default. * * @param s * start of span. * @param e * end of span, which is +1 more than the last element in the * span. * @param type * the type of the span */ public Span(int s, int e, String type) { if (s < 0) { throw new IllegalArgumentException("start index must be zero or greater: " + s); } if (e < 0) { throw new IllegalArgumentException("end index must be zero or greater: " + e); } if (s > e) { throw new IllegalArgumentException( "start index must not be larger than end index: " + "start=" + s + ", end=" + e); } start = s; end = e; this.type = type; this.prob = 0d; } public Span(int s, int e, String type, double prob) { if (s < 0) { throw new IllegalArgumentException("start index must be zero or greater: " + s); } if (e < 0) { throw new IllegalArgumentException("end index must be zero or greater: " + e); } if (s > e) { throw new IllegalArgumentException( "start index must not be larger than end index: " + "start=" + s + ", end=" + e); } start = s; end = e; this.prob = prob; this.type = type; } /** * Initializes a new Span Object. Sets the prob to 0 as default * * @param s * start of span. * @param e * end of span. */ public Span(int s, int e) { this(s, e, null, 0d); } /** * * @param s * the start of the span (the token index, not the char index) * @param e * the end of the span (the token index, not the char index) * @param prob The probability of the span. */ public Span(int s, int e, double prob) { this(s, e, null, prob); } /** * Initializes a new Span object with an existing Span which is shifted by * an offset. * * @param span The {@link Span}. * @param offset Shift the span by this offset. */ public Span(Span span, int offset) { this(span.start + offset, span.end + offset, span.getType(), span.getProb()); } /** * Creates a new immutable span based on an existing span, where the * existing span did not include the prob * * @param span * the span that has no prob or the prob is incorrect and a new * Span must be generated * @param prob * the probability of the span */ public Span(Span span, double prob) { this(span.start, span.end, span.getType(), prob); } public static String[] spansToStrings(Span[] spans, CharSequence s) { String[] tokens = new String[spans.length]; for (int si = 0, sl = spans.length; si < sl; si++) { tokens[si] = spans[si].getCoveredText(s).toString(); } return tokens; } public CharSequence getCoveredText(CharSequence text) { if (getEnd() > text.length()) { throw new IllegalArgumentException( "The span " + toString() + " is outside the given text which has length " + text.length() + "!"); } return text.subSequence(getStart(), getEnd()); } public int getStart() { return start; } public int getEnd() { return end; } public String getType() { return type; } public double getProb() { return prob; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/Stemmer.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp; /** * Interface for a text stemmer. * * @author Mountain Fog, Inc. * */ @FunctionalInterface public interface Stemmer { /** * Stems text. * @param text The text to stem. * @return The stemmed text. */ public String stem(String text); }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/Tokenizer.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp; import java.util.List; /** * The interface for tokenizers, which segment a string into its tokens. * <p> * Tokenization is a necessary step before more complex NLP tasks can be applied, * these usually process text on a token level. The quality of tokenization is * important because it influences the performance of high-level task applied to it. * <p> * In segmented languages like English most words are segmented by white spaces * expect for punctuations, etc. which is directly attached to the word without a white space * in between, it is not possible to just split at all punctuations because in abbreviations dots * are a part of the token itself. A tokenizer is now responsible to split these tokens * correctly. * <p> * In non-segmented languages like Chinese tokenization is more difficult since words * are not segmented by a whitespace. * <p> * Tokenizers can also be used to segment already identified tokens further into more * atomic parts to get a deeper understanding. This approach helps more complex task * to gain insight into tokens which do not represent words like numbers, units or tokens * which are part of a special notation. * <p> * For most further task it is desirable to over tokenize rather than under tokenize. * <p> * This class is based on OpenNLP's <code>opennlp.tools.tokenize.Tokenizer</code>. */ public interface Tokenizer { /** * Gets the ISO 639-2 language codes supported by this tokenizer. * @return A list of ISO 639-2 language codes supported by the tokenizer, * or an empty list if the tokenizer is not language-dependent. */ List<String> getLanguageCodes(); /** * Splits a string into its atomic parts * * @param s The string to be tokenized. * @return The String[] with the individual tokens as the array * elements. */ String[] tokenize(String s); /** * Finds the boundaries of atomic parts in a string. * * @param s The string to be tokenized. * @return The Span[] with the spans (offsets into s) for each * token as the individuals array elements. */ Span[] tokenizePos(String s); /** * Splits a string into its atomic parts and stems the parts. * * @param s The string to be tokenized. * @param stemmer The {@link Stemmer} to be used during tokenization. * @return The String[] with the individual stemmed tokens as the array * elements. */ String[] tokenize(String s, Stemmer stemmer); }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/annotation/AnnotationReader.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.annotation; import java.util.Collection; /** * Provides access to annotations stored in an external source (file, database, etc.). * * @author Mountain Fog, Inc. * */ @FunctionalInterface public interface AnnotationReader { /** * Retrieves the annotations for a given line number. * @param lineNumber The line number in the text. * @return A collection of {@link IdylNLPAnnotation annotations}. */ public Collection<IdylNLPAnnotation> getAnnotations(int lineNumber); }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/annotation/AnnotationTypes.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.annotation; public enum AnnotationTypes { BRAT("brat"), CONLL2003("conll2003"), OPENNLP("opennlp"), IDYLNLP("idylnlp"); private String name; private AnnotationTypes(String name) { this.name = name; } public String getName() { return name; } @Override public String toString() { return name; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/annotation/IdylNLPAnnotation.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.annotation; import org.apache.commons.lang3.builder.ToStringBuilder; /** * An Idyl NLP annotation. * * @author Mountain Fog, Inc. * */ public class IdylNLPAnnotation { private int lineNumber; private int tokenStart; private int tokenEnd; private String type; /** * Creates a new annotation. * @param lineNumber The line number in the text that contains the entity. * @param tokenStart The token-based start position of the entity. * @param tokenEnd THe token-based end position of the entity. * @param type The type of entity. */ public IdylNLPAnnotation(int lineNumber, int tokenStart, int tokenEnd, String type) { this.lineNumber = lineNumber; this.tokenStart = tokenStart; this.tokenEnd = tokenEnd; this.type = type; } /** * Creates a new annotation. */ public IdylNLPAnnotation() { } @Override public String toString() { return ToStringBuilder.reflectionToString(this); } public int getTokenStart() { return tokenStart; } public void setTokenStart(int tokenStart) { this.tokenStart = tokenStart; } public int getTokenEnd() { return tokenEnd; } public void setTokenEnd(int tokenEnd) { this.tokenEnd = tokenEnd; } public String getType() { return type; } public void setType(String type) { this.type = type; } public int getLineNumber() { return lineNumber; } public void setLineNumber(int lineNumber) { this.lineNumber = lineNumber; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/documents/AbstractDocumentClassificationRequest.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.documents; import com.neovisionaries.i18n.LanguageCode; /** * Base class for document classification requests. * * @author Mountain Fog, Inc. * */ public class AbstractDocumentClassificationRequest { private String text; private LanguageCode languageCode; /** * Creates a new document classification request. * @param text The tokenized text to classify. * @param languageCode The {@link LanguageCode} of the language. */ public AbstractDocumentClassificationRequest(String text, LanguageCode languageCode) { this.text = text; this.languageCode = languageCode; } public String getText() { return text; } public void setText(String text) { this.text = text; } public LanguageCode getLanguageCode() { return languageCode; } public void setLanguageCode(LanguageCode languageCode) { this.languageCode = languageCode; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/documents/AbstractDocumentClassifierConfiguration.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.documents; /** * Base class for document classifier configurations. * * @author Mountain Fog, Inc. * */ public abstract class AbstractDocumentClassifierConfiguration { }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/documents/AbstractDocumentClassifierTrainingRequest.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.documents; import java.io.File; import com.neovisionaries.i18n.LanguageCode; /** * Base class for a document classifier training request. * * @author Mountain Fog, Inc. * */ public class AbstractDocumentClassifierTrainingRequest { private File trainingFile; private String encryptionKey; private LanguageCode languageCode; public AbstractDocumentClassifierTrainingRequest(File trainingFile, LanguageCode languageCode) { this.trainingFile = trainingFile; this.languageCode = languageCode; } public File getTrainingFile() { return trainingFile; } public void setTrainingFile(File trainingFile) { this.trainingFile = trainingFile; } public String getEncryptionKey() { return encryptionKey; } public void setEncryptionKey(String encryptionKey) { this.encryptionKey = encryptionKey; } public LanguageCode getLanguageCode() { return languageCode; } public void setLanguageCode(LanguageCode languageCode) { this.languageCode = languageCode; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/documents/DeepLearningDocumentClassificationRequest.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.documents; import com.neovisionaries.i18n.LanguageCode; /** * A request for document classification using a deep learning model. * The input text should be tokenized. * * @author Mountain Fog, Inc. * */ public class DeepLearningDocumentClassificationRequest extends AbstractDocumentClassificationRequest { public DeepLearningDocumentClassificationRequest(String text, LanguageCode languageCode) { super(text, languageCode); } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/documents/DeepLearningDocumentClassifierTrainingRequest.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.documents; import java.util.List; import com.neovisionaries.i18n.LanguageCode; /** * A deep learning document classifier training request. * * @author Mountain Fog, Inc. * */ public class DeepLearningDocumentClassifierTrainingRequest extends DocumentClassifierTrainingRequest { // Defines minimal word frequency in training corpus. All words below this threshold will be removed prior model training. private int minWordFrequency = 1; // Defines number of dimensions for output vectors private int layerSize = 100; // Number of examples in each minibatch private int batchSize = 64; // Number of epochs (full passes of training data) to train on private int epochs = 1; // Truncate reviews with length (# words) greater than this private int truncateToLength = 256; private double learningRate = 0.025; private double minLearningRate = 0.001; private LanguageCode languageCode; private List<String> directories; public DeepLearningDocumentClassifierTrainingRequest() { } public DeepLearningDocumentClassifierTrainingRequest(LanguageCode languageCode, List<String> directories) { this.languageCode = languageCode; this.setDirectories(directories); } public LanguageCode getLanguageCode() { return languageCode; } public void setLanguageCode(LanguageCode languageCode) { this.languageCode = languageCode; } public int getBatchSize() { return batchSize; } public void setBatchSize(int batchSize) { this.batchSize = batchSize; } public int getTruncateToLength() { return truncateToLength; } public void setTruncateToLength(int truncateToLength) { this.truncateToLength = truncateToLength; } public int getEpochs() { return epochs; } public void setEpochs(int epochs) { this.epochs = epochs; } public List<String> getDirectories() { return directories; } public void setDirectories(List<String> directories) { this.directories = directories; } public double getLearningRate() { return learningRate; } public void setLearningRate(double learningRate) { this.learningRate = learningRate; } public double getMinLearningRate() { return minLearningRate; } public void setMinLearningRate(double minLearningRate) { this.minLearningRate = minLearningRate; } public int getMinWordFrequency() { return minWordFrequency; } public void setMinWordFrequency(int minWordFrequency) { this.minWordFrequency = minWordFrequency; } public int getLayerSize() { return layerSize; } public void setLayerSize(int layerSize) { this.layerSize = layerSize; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/documents/DocumentClassificationEvaluationRequest.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.documents; import com.neovisionaries.i18n.LanguageCode; public class DocumentClassificationEvaluationRequest { private LanguageCode languageCode; private String directory; public LanguageCode getLanguageCode() { return languageCode; } public void setLanguageCode(LanguageCode languageCode) { this.languageCode = languageCode; } public String getDirectory() { return directory; } public void setDirectory(String directory) { this.directory = directory; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/documents/DocumentClassificationEvaluationResponse.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.documents; import java.util.Map; import java.util.concurrent.atomic.AtomicInteger; public class DocumentClassificationEvaluationResponse { private Map<String, Map<String, AtomicInteger>> results; public DocumentClassificationEvaluationResponse(Map<String, Map<String, AtomicInteger>> results) { this.results = results; } public Map<String, Map<String, AtomicInteger>> getResults() { return results; } public void setResults(Map<String, Map<String, AtomicInteger>> results) { this.results = results; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/documents/DocumentClassificationFile.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.documents; /** * A file produced as the result of training a document * classification model. * * @author Mountain Fog, Inc. * */ public enum DocumentClassificationFile { /** * A model file. */ MODEL_FILE("Model"), MODEL_MANIFEST("Model Manifest"); private String description; private DocumentClassificationFile(String description) { this.description = description; } public String getDescription() { return description; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/documents/DocumentClassificationResponse.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.documents; /** * The response from classifying a document. * * @author Mountain Fog, Inc. * */ public class DocumentClassificationResponse { private DocumentClassificationScores scores; public DocumentClassificationResponse(DocumentClassificationScores scores) { this.scores = scores; } public DocumentClassificationScores getScores() { return scores; } public void setScores(DocumentClassificationScores scores) { this.scores = scores; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/documents/DocumentClassificationScores.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.documents; import java.util.Collections; import java.util.Map; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; public class DocumentClassificationScores { private Map<String, Double> scores; public DocumentClassificationScores(Map<String, Double> scores) { this.scores = scores; } public Pair<String, Double> getPredictedCategory() { final String maxEntry = Collections.max(scores.entrySet(), Map.Entry.comparingByValue()).getKey(); return new ImmutablePair<String, Double>(maxEntry, scores.get(maxEntry)); } public Map<String, Double> getScores() { return scores; } public void setScores(Map<String, Double> scores) { this.scores = scores; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/documents/DocumentClassificationTrainingResponse.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.documents; import java.io.File; import java.util.List; import java.util.Map; /** * The response from training a document classification model. * * @author Mountain Fog, Inc. * */ public class DocumentClassificationTrainingResponse { private String modelId; private Map<DocumentClassificationFile, File> files; private List<String> categories; public DocumentClassificationTrainingResponse(String modelId, Map<DocumentClassificationFile, File> files, List<String> categories) { this.modelId = modelId; this.files = files; this.categories = categories; } public String getModelId() { return modelId; } public void setModelId(String modelId) { this.modelId = modelId; } public Map<DocumentClassificationFile, File> getFiles() { return files; } public void setFiles(Map<DocumentClassificationFile, File> files) { this.files = files; } public List<String> getCategories() { return categories; } public void setCategories(List<String> categories) { this.categories = categories; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/documents/DocumentClassifier.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.documents; /** * An interface for document classifiers. A document classifier takes a document * and assigns it to one or more known classes based on the document's contents. * * @author Mountain Fog, Inc. * */ public interface DocumentClassifier<T extends AbstractDocumentClassifierConfiguration, U extends AbstractDocumentClassificationRequest> { /** * Classifies a document. * @param request A {@link AbstractDocumentClassificationRequest request} containing the details of the * document classification request. * @return A {@link DocumentClassificationResponse response} containing the results of the * document classification. * @throws DocumentClassifierException Thrown if the document classification fails. */ public DocumentClassificationResponse classify(U request) throws DocumentClassifierException; /** * Evaluates a document classification model. * @param request The {@link DocumentClassificationEvaluationRequest request} to evaluate. * @return The {@link DocumentClassificationEvaluationResponse results} of the evaluation. * @throws DocumentClassifierException Thrown if the evaluation fails. */ public DocumentClassificationEvaluationResponse evaluate(DocumentClassificationEvaluationRequest request) throws DocumentClassifierException; }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/documents/DocumentClassifierException.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.documents; /** * An exception thrown during the classification of a document. * * @author Mountain Fog, Inc. * */ public class DocumentClassifierException extends Exception { private static final long serialVersionUID = -8390739685887961751L; /** * Creates a new exception. * @param message The exception message. */ public DocumentClassifierException(String message) { super(message); } /** * Creates a new exception. * @param message The exception message. * @param ex The underlying {@link Exception}. */ public DocumentClassifierException(String message, Exception ex) { super(message, ex); } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/documents/DocumentClassifierModelOperations.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.documents; public interface DocumentClassifierModelOperations<T extends DocumentClassifierTrainingRequest> { /** * Trains a document classifier model. * @param request A {@link DocumentClassifierTrainingRequest} containing the details * of the training request. * @throws DocumentClassifierException Thrown if the training fails. */ public DocumentClassificationTrainingResponse train(T request) throws DocumentModelTrainingException; }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/documents/DocumentClassifierTrainingRequest.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.documents; /** * Base class for document classification training request. * * @author Mountain Fog, Inc. * */ public abstract class DocumentClassifierTrainingRequest { }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/documents/DocumentModelTrainingException.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.documents; /** * An exception thrown during the training of a classification model. * * @author Mountain Fog, Inc. * */ public class DocumentModelTrainingException extends Exception { private static final long serialVersionUID = -8390739685887961751L; /** * Creates a new exception. * @param message The exception message. */ public DocumentModelTrainingException(String message) { super(message); } /** * Creates a new exception. * @param message The exception message. * @param ex The underlying {@link Exception}. */ public DocumentModelTrainingException(String message, Exception ex) { super(message, ex); } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/documents/OpenNLPDocumentClassificationRequest.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.documents; import com.neovisionaries.i18n.LanguageCode; /** * A request for document classification. The input text * should be tokenized. * * @author Mountain Fog, Inc. * */ public class OpenNLPDocumentClassificationRequest extends AbstractDocumentClassificationRequest { public OpenNLPDocumentClassificationRequest(String text, LanguageCode languageCode) { super(text, languageCode); } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/documents/OpenNLPDocumentClassifierTrainingRequest.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.documents; import java.io.File; import com.neovisionaries.i18n.LanguageCode; /** * A request to train a document classification model using OpenNLP. * * @author Mountain Fog, Inc. * */ public class OpenNLPDocumentClassifierTrainingRequest extends DocumentClassifierTrainingRequest { private File trainingFile; private String encryptionKey; private LanguageCode languageCode; /** * Creates a new classification request. * @param trainingFile The {@link File file} containing the training data. * @param languageCode The {@link LanguageCode language} of the training data. */ public OpenNLPDocumentClassifierTrainingRequest(File trainingFile, LanguageCode languageCode) { this.trainingFile = trainingFile; this.languageCode = languageCode; } public File getTrainingFile() { return trainingFile; } public void setTrainingFile(File trainingFile) { this.trainingFile = trainingFile; } public String getEncryptionKey() { return encryptionKey; } public void setEncryptionKey(String encryptionKey) { this.encryptionKey = encryptionKey; } public LanguageCode getLanguageCode() { return languageCode; } public void setLanguageCode(LanguageCode languageCode) { this.languageCode = languageCode; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/language/LanguageDetectionException.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.language; /** * Exception thrown for errors during language detection * operations. * * @author Mountain Fog, Inc. * */ public class LanguageDetectionException extends Exception { private static final long serialVersionUID = -8000602757640799852L; public LanguageDetectionException(String message) { super(message); } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/language/LanguageDetectionResponse.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.language; import java.util.List; import org.apache.commons.lang3.tuple.Pair; public class LanguageDetectionResponse { private List<Pair<String, Double>> languages; public LanguageDetectionResponse(List<Pair<String, Double>> languages) { this.languages = languages; } public List<Pair<String, Double>> getLanguages() { return languages; } public void setLanguages(List<Pair<String, Double>> languages) { this.languages = languages; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/language/LanguageDetector.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.language; /** * Interface for language detectors. A language detector accepts a String input * and then determines the language of the input. * * @author Mountain Fog, Inc. * */ @FunctionalInterface public interface LanguageDetector { LanguageDetectionResponse detectLanguage(String text, int limit) throws LanguageDetectionException; }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/language/StopWordRemover.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.language; import java.util.Collection; /** * Interface for stop word removers. * * @author Mountain Fog, Inc. * */ public interface StopWordRemover { /** * Determines if the input string is a stop word. * @param input The input string. * @return True if the input is a stop word. */ public boolean isStopWord(String input); /** * Removes all (if any) stop words from the input strings. * @param input A collection of input strings. * @return A subset of the input minus strings that were stop words. */ public Collection<String> removeStopWords(Collection<String> input); }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/lemma/Lemmatizer.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.lemma; /** * Defines a lemmatizer. * * @author Mountain Fog, Inc. * */ @FunctionalInterface public interface Lemmatizer { /** * Lemmatizes the tokens. * @param tokens The tokens. * @param posTags The tokens' part-of-speech tags. * @return The lemmas of the tokens. */ public String[] lemmatize(String[] tokens, String posTags[]); }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/ner/EntityExtractionRequest.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.ner; import java.util.LinkedHashMap; import java.util.Map; import com.neovisionaries.i18n.LanguageCode; import ai.idylnlp.model.nlp.DuplicateEntityStrategy; import ai.idylnlp.model.nlp.EntityOrder; import ai.idylnlp.model.nlp.Location; import ai.idylnlp.model.nlp.pipeline.PipelineRequest; /** * Request to extract entities from text. * * @author Mountain Fog, Inc. */ public class EntityExtractionRequest extends PipelineRequest { private String[] text; private int confidenceThreshold = 0; private LanguageCode languageCode = null; private String context = "not-set"; private EntityOrder order = EntityOrder.OCCURRENCE; private Location location; private DuplicateEntityStrategy duplicateEntityStrategy; private Map<String, String> metadata; private String type = null; private boolean includeModelFileNameInMetadata = true; /** * Create a request to extract entities. This request will use * a confidence threshold of zero unless manually set. * It is assumed the input language is English. * @param text The text to extract entities from. */ public EntityExtractionRequest(String[] text) { this.text = text; this.metadata = new LinkedHashMap<String, String>(); } /** * Sets the entity metadata. * @param metadata The entity metadata. * @return The {@link EntityExtractionRequest}. */ public EntityExtractionRequest withMetadata(Map<String, String> metadata) { this.metadata = metadata; return this; } /** * Sets the confidence threshold. * @param confidenceThreshold The confidence threshold. * @return The {@link EntityExtractionRequest}. */ public EntityExtractionRequest withConfidenceThreshold(int confidenceThreshold) { this.confidenceThreshold = confidenceThreshold; return this; } /** * Sets the extraction context. This value does not have to be unique. * @param context The context for the extraction. * @return The {@link EntityExtractionRequest}. */ public EntityExtractionRequest withContext(String context) { this.context = context; return this; } /** * Sets the type of entity to extract. * @param type The type of entity to extract. * @return The {@link EntityExtractionRequest}. */ public EntityExtractionRequest withType(String type) { this.type = type; return this; } /** * * @param language The {@link LanguageCode} of the input text. * @return The {@link EntityExtractionRequest}. */ public EntityExtractionRequest withLanguage(LanguageCode language) { this.languageCode = language; return this; } /** * The sort {@link EntityOrder order} for the returned entities. * @param order The sort {@link EntityOrder order} for the returned entities. * @return Returns a reference to this object so that method calls can be chained together. */ public EntityExtractionRequest withOrder(EntityOrder order) { this.order = order; return this; } /** * Sets a {@link Location location} attribute for the entity extraction request. * @param location The {@link Location location}. * @return Returns a reference to this object so that method calls can be chained together. */ public EntityExtractionRequest withLocation(Location location) { this.location = location; return this; } /** * Sets the duplicate entity {@link DuplicateEntityStrategy strategy}. If set this value overrides * the duplicate entity strategy set for the pipeline for this request only. * @param duplicateEntityStrategy The {@link DuplicateEntityStrategy strategy}. * @return Returns a reference to this object so that method calls can be chained together. */ public EntityExtractionRequest withDuplicateEntityStrategy(DuplicateEntityStrategy duplicateEntityStrategy) { this.duplicateEntityStrategy = duplicateEntityStrategy; return this; } /** * Whether or not to include the filename of the model that extracted the entity in * the entity's metadata. * @param includeModelFileNameInMetadata A boolean indicating whether or not to include the * filename of the model that extracted this entity. * @return Returns a reference to this object so that method calls can be chained together. */ public EntityExtractionRequest withIncludeModelFileNameInMetadata(boolean includeModelFileNameInMetadata) { this.includeModelFileNameInMetadata = includeModelFileNameInMetadata; return this; } @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("Text: " + text + "; Confidence Threshold: " + confidenceThreshold + "; Context: " + context + "; Language: " + languageCode.getAlpha3().toString() + "; "); return sb.toString(); } /** * Gets the value of the confidence threshold. * @return The value of the confidence threshold. */ public int getConfidenceThreshold() { return confidenceThreshold; } /** * Sets the value of the confidence threshold. * @param confidenceThreshold The value of the confidence threshold. Valid values are 0-100. */ public void setConfidenceThreshold(int confidenceThreshold) { this.confidenceThreshold = confidenceThreshold; } /** * Gets the text to be processed. * @return The text to be processed. */ public String[] getText() { return text; } /** * Gets the language of the input text. * @return The {@link LanguageCode} of the input text. */ public LanguageCode getLanguage() { return languageCode; } /** * Sets the language of the input text. * @param languageCode The {@link LanguageCode}. */ public void setLanguage(LanguageCode languageCode) { this.languageCode = languageCode; } /** * Gets the context used for the extraction. * @return The context. */ public String getContext() { return context; } /** * Gets the sort {@link EntityOrder order} for the returned entities. * @return The sort {@link EntityOrder order} for the returned entities. */ public EntityOrder getOrder() { return order; } /** * Sets the sort {@link EntityOrder order} for the returned entities. * @param order The {@link EntityOrder order} for the returned entities. */ public void setOrder(EntityOrder order) { this.order = order; } /** * Sets the context for the extraction. * @param context The context for the extraction. */ public void setContext(String context) { this.context = context; } /** * Gets the {@link Location location} attribute. * @return The {@link Location location}. */ public Location getLocation() { return location; } /** * Sets the {@link Location location} attribute. * @param location The {@link Location location}. */ public void setLocation(Location location) { this.location = location; } /** * Gets the duplicate entity strategy. * @return The duplicate entity {@link DuplicateEntityStrategy strategy}. */ public DuplicateEntityStrategy getDuplicateEntityStrategy() { return duplicateEntityStrategy; } /** * Sets the duplicate entity strategy. This value overrides * the duplicate entity strategy set for the pipeline for this request only. * @param duplicateEntityStrategy The duplicate entity {@link DuplicateEntityStrategy strategy}. */ public void setDuplicateEntityStrategy(DuplicateEntityStrategy duplicateEntityStrategy) { this.duplicateEntityStrategy = duplicateEntityStrategy; } /** * Gets the entity metadata. * @return The entity metadata. */ public Map<String, String> getMetadata() { return metadata; } /** * Sets the entity metadata. * @param metadata The entity metadata. */ public void setMetadata(Map<String, String> metadata) { this.metadata = metadata; } /** * Gets the type of entity to extract. * @return The type of entity to extract. */ public String getType() { return type; } /** * Sets the type of entity to extract. * @param type The type of entity to extract. */ public void setType(String type) { this.type = type; } /** * Gets whether or not to include the model's filename that extracted the * entity in the entity metadata. * @return Whether or not to include the model's filename that extracted the * entity in the entity metadata. */ public boolean isIncludeModelFileNameInMetadata() { return includeModelFileNameInMetadata; } /** * Sets whether or not to include the model's filename that extracted the * entity in the entity metadata. * @param includeModelFileNameInMetadata <code>true</code> to include the model's filename * in the entity's metadata; otherwise <code>false</code>. */ public void setIncludeModelFileNameInMetadata( boolean includeModelFileNameInMetadata) { this.includeModelFileNameInMetadata = includeModelFileNameInMetadata; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/ner/EntityExtractionResponse.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.ner; import java.util.Set; import ai.idylnlp.model.entity.Entity; import ai.idylnlp.model.nlp.pipeline.PipelineResponse; /** * Response to an entity extraction request. * @author Mountain Fog, Inc. */ public class EntityExtractionResponse extends PipelineResponse { private Set<Entity> entities; private long extractionTime; private boolean successful; /** * Creates a response to a request to extract entities. * @param entities A collection of {@link Entity} objects. * @param extractionTime The extraction time in milliseconds. * @param successful Indicates if the extraction was successful. */ public EntityExtractionResponse(Set<Entity> entities, long extractionTime, boolean successful) { this.entities = entities; this.extractionTime = extractionTime; this.successful = successful; } /** * Gets the extracted entities. * @return A collection of extracted entities. */ public Set<Entity> getEntities() { return entities; } /** * Gets the time spent in milliseconds extracting the entities. This * value can be monitored to maintain a certain performance level. * @return The time spent in milliseconds to extract the entities. */ public long getExtractionTime() { return extractionTime; } /** * Indicates if the extraction was successful. * @return <code>true</code> if the extraction was successful. */ public boolean isSuccessful() { return successful; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/ner/EntityRecognizer.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.ner; import ai.idylnlp.model.exceptions.EntityFinderException; import ai.idylnlp.model.exceptions.ModelLoaderException; /** * Interface for entity recognizers. * @author Mountain Fog, Inc. */ public interface EntityRecognizer { /** * Extracts entities. Implementations of this function likely need to be <code>synchronized</code>. * @param request {@link EntityExtractionRequest} that contains the text to process and input parameters. * @return {@link EntityExtractionResponse} that contains the extracted entities. * @throws EntityFinderException Thrown when entity extraction fails. * @throws ModelLoaderException Thrown when the model cannot be loaded. */ public EntityExtractionResponse extractEntities(EntityExtractionRequest request) throws EntityFinderException, ModelLoaderException; }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/pipeline/Pipeline.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.pipeline; @FunctionalInterface public interface Pipeline<T extends PipelineResponse> { /** * Execute the pipeline. * @param request The input to the pipeline. * @return The response from the pipeline. */ T run(String text); }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/pipeline/PipelineRequest.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.pipeline; public abstract class PipelineRequest { }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/pipeline/PipelineResponse.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.pipeline; public abstract class PipelineResponse { }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/pos/PartsOfSpeechTagger.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.pos; import java.util.List; import ai.idylnlp.model.nlp.SentenceDetector; import ai.idylnlp.model.nlp.Tokenizer; /** * A part of speech (POS) tagger. * * @author Mountain Fog, Inc. * */ public interface PartsOfSpeechTagger { /** * Tags the tokens in the input. The input is broken into sentences and tokenized. * @param input The input. * @param sentenceDetector A {@link SentenceDetector}. * @param tokenizer A {@link Tokenizer}. * @return A list of {@link PartsOfSpeechToken}. */ public List<PartsOfSpeechToken> tag(String input, SentenceDetector sentenceDetector, Tokenizer tokenizer); /** * Tags the tokens in the sentences. Each sentence will be tokenized. * @param sentences An array of sentences. * @param tokenizer A {@link Tokenizer}. * @return A list of {@link PartsOfSpeechToken}. */ public List<PartsOfSpeechToken> tag(String[] sentences, Tokenizer tokenizer); /** * Tags the tokens in the tokenized sentence. * @param tokenizedSentence A single tokenized sentence. * @return A list of {@link PartsOfSpeechToken}. */ public List<PartsOfSpeechToken> tag(String[] tokenizedSentence); }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/pos/PartsOfSpeechToken.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.pos; import java.util.LinkedList; import java.util.List; public class PartsOfSpeechToken { private String token; private String pos; public PartsOfSpeechToken(String token, String pos) { this.token = token; this.pos = pos; } public static String[] getTokens(List<PartsOfSpeechToken> partsOfSpeechTokens) { List<String> tags = new LinkedList<String>(); for(PartsOfSpeechToken partsOfSpeechToken : partsOfSpeechTokens) { tags.add(partsOfSpeechToken.getPos()); } return tags.toArray(new String[tags.size()]); } public String getToken() { return token; } public String getPos() { return pos; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/sentiment/Sentiment.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.sentiment; /** * Represents a sentiment. * * @author Mountain Fog, Inc. * */ public class Sentiment { private String sentimentName; private int sentimentValue; /** * Creates a new Sentiment. * @param sentimentName The name the sentiment. * @param sentimentValue The value of the sentiment. */ public Sentiment(String sentimentName, int sentimentValue) { this.sentimentName = sentimentName; this.sentimentValue = sentimentValue; } /** * Gets the name of the sentiment. * @return The name of the sentiment. */ public String getSentimentName() { return sentimentName; } /** * Gets the integer value of the sentiment. * @return The integer value of the sentiment. */ public int getSentimentValue() { return sentimentValue; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/sentiment/SentimentAnalysisException.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.sentiment; public class SentimentAnalysisException extends Exception { private static final long serialVersionUID = 2601902299898556318L; public SentimentAnalysisException(String message, Exception ex) { super(message, ex); } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/sentiment/SentimentAnalysisRequest.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.sentiment; import java.io.Serializable; public class SentimentAnalysisRequest implements Serializable { private static final long serialVersionUID = -5785895999181600968L; private String text; public SentimentAnalysisRequest(String text) { this.text = text; } public String getText() { return text; } public void setText(String text) { this.text = text; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/sentiment/SentimentAnalyzer.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.sentiment; /** * Interface for sentiment analyzers. * * @author Mountain Fog, Inc. * */ public interface SentimentAnalyzer { /** * Determine the sentiment of the input text. * @param request The sentiment analysis {@link SentimentAnalysisRequest request}. * @return A {@link Sentiment}. * @throws SentimentAnalysisException Thrown if the sentiment analysis fails. */ public Sentiment analyze(SentimentAnalysisRequest request) throws SentimentAnalysisException; /** * Gets the label of the sentiment. * @return The label of the sentiment. */ public String getSentimentLabel(); /** * Gets the name of the sentiment analyzer. * @return The name of the sentiment analyzer. */ public String getName(); }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/sentiment/SentimentDefinition.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.sentiment; import ai.idylnlp.model.nlp.Stemmer; /** * A definition of a sentiment. * * @author Mountain Fog, Inc. * */ public class SentimentDefinition { private String sentimentLabel; private String fileName; private String fullFilePath; private boolean enableFuzzyMatching; private boolean enableStemming; private Stemmer stemmer; public SentimentDefinition(String sentimentLabel, String fileName, String fullFilePath) { this.sentimentLabel = sentimentLabel; this.fileName = fileName; this.fullFilePath = fullFilePath; this.enableFuzzyMatching = false; this.enableStemming = false; } public SentimentDefinition(String sentimentLabel, String fileName, String fullFilePath, boolean enableFuzzyMatching, boolean enableStemming, Stemmer stemmer) { this.sentimentLabel = sentimentLabel; this.fileName = fileName; this.fullFilePath = fullFilePath; this.enableFuzzyMatching = enableFuzzyMatching; this.enableStemming = enableStemming; this.stemmer = stemmer; } public SentimentDefinition(String sentimentLabel, String fileName, String fullFilePath, boolean enableFuzzyMatching, int maxFuzziness, boolean enableStemming, Stemmer stemmer) { this.sentimentLabel = sentimentLabel; this.fileName = fileName; this.fullFilePath = fullFilePath; this.enableFuzzyMatching = enableFuzzyMatching; this.enableStemming = enableStemming; this.stemmer = stemmer; } @Override public String toString() { return String.format("Sentiment Label: %s; Definition File: %s", sentimentLabel, fileName); } public String getFileName() { return fileName; } public void setFileName(String fileName) { this.fileName = fileName; } public boolean isEnableFuzzyMatching() { return enableFuzzyMatching; } public void setEnableFuzzyMatching(boolean enableFuzzyMatching) { this.enableFuzzyMatching = enableFuzzyMatching; } public String getSentimentLabel() { return sentimentLabel; } public void setSentimentLabel(String sentimentLabel) { this.sentimentLabel = sentimentLabel; } public String getFullFilePath() { return fullFilePath; } public void setFullFilePath(String fullFilePath) { this.fullFilePath = fullFilePath; } public boolean isEnableStemming() { return enableStemming; } public void setEnableStemming(boolean enableStemming) { this.enableStemming = enableStemming; } public Stemmer getStemmer() { return stemmer; } public void setStemmer(Stemmer stemmer) { this.stemmer = stemmer; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/strings/Distance.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.strings; /** * Interface for calculating the distances between strings. * Distance and similarity are complementary. * * @author Mountain Fog, Inc. * */ public interface Distance extends StringMetrics { }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/strings/Similarity.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.strings; /** * Interface for calculating the similarity between strings. * Similarity and distance are complementary. * * @author Mountain Fog, Inc. * */ public interface Similarity extends StringMetrics { }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/strings/StringMetrics.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.strings; /** * Interface for string metrics calculations. * * @author Mountain Fog, Inc. * */ public abstract interface StringMetrics { /** * Calculate the distance or similarity between two strings. * @param s An input string. * @param t An input string. * @return The distance or similarity between the two input strings. */ double calculate(CharSequence s, CharSequence t); }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/strings
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/strings/distancestrategy/ConstantMaxDistanceStrategy.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.strings.distancestrategy; public class ConstantMaxDistanceStrategy implements MaxDistanceStrategy { private int length; public ConstantMaxDistanceStrategy(int length) { this.length = length; } @Override public int calculateMaxDistance(String word) { return length; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/strings
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/strings/distancestrategy/MaxDistanceStrategy.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.strings.distancestrategy; @FunctionalInterface public interface MaxDistanceStrategy { public int calculateMaxDistance(String word); }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/strings
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/strings/distancestrategy/WordLengthBasedMaxDistanceStrategy.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.strings.distancestrategy; public class WordLengthBasedMaxDistanceStrategy implements MaxDistanceStrategy { @Override public int calculateMaxDistance(String word) { return Math.round(word.length() / 5); } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/subjects/BratSubjectOfTrainingOrEvaluation.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.subjects; public class BratSubjectOfTrainingOrEvaluation extends SubjectOfTrainingOrEvaluation { public BratSubjectOfTrainingOrEvaluation(String inputFile) { super(inputFile); } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/subjects/CoNLL2003SubjectOfTrainingOrEvaluation.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.subjects; public class CoNLL2003SubjectOfTrainingOrEvaluation extends SubjectOfTrainingOrEvaluation { public CoNLL2003SubjectOfTrainingOrEvaluation(String inputFile) { super(inputFile); } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/subjects/DefaultSubjectOfTrainingOrEvaluation.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.subjects; public class DefaultSubjectOfTrainingOrEvaluation extends SubjectOfTrainingOrEvaluation { public DefaultSubjectOfTrainingOrEvaluation(String inputFile) { super(inputFile); } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/subjects/IdylNLPSubjectOfTrainingOrEvaluation.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.subjects; public class IdylNLPSubjectOfTrainingOrEvaluation extends SubjectOfTrainingOrEvaluation { private String annotationsFile; public IdylNLPSubjectOfTrainingOrEvaluation(String inputFile, String annotationsFile) { super(inputFile); this.annotationsFile = annotationsFile; } public String getAnnotationsFile() { return annotationsFile; } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/subjects/OpenNLPSubjectOfTrainingOrEvaluation.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.subjects; public class OpenNLPSubjectOfTrainingOrEvaluation extends SubjectOfTrainingOrEvaluation { public OpenNLPSubjectOfTrainingOrEvaluation(String inputFile) { super(inputFile); } }
0
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp
java-sources/ai/idylnlp/idylnlp-model/1.1.0/ai/idylnlp/model/nlp/subjects/SubjectOfTrainingOrEvaluation.java
/******************************************************************************* * Copyright 2018 Mountain Fog, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy * of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. ******************************************************************************/ package ai.idylnlp.model.nlp.subjects; /** * Base class for training or evaluation subjects. * * @author Mountain Fog, Inc. * */ public abstract class SubjectOfTrainingOrEvaluation { private String inputFile; public SubjectOfTrainingOrEvaluation(String inputFile) { this.inputFile = inputFile; } public String getInputFile() { return inputFile; } }