Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(#276): loading the model during compilation #303

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,24 @@ SOFTWARE.
<artifactId>jmh-maven-plugin</artifactId>
<version>0.2.2</version>
</plugin>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>1.9.0</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>https://opennlp.sourceforge.net/models-1.5/en-pos-perceptron.bin</url>
<outputFileName>en-pos-perceptron.bin</outputFileName>
<outputDirectory>${project.build.directory}/classes</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
18 changes: 4 additions & 14 deletions src/main/java/org/eolang/lints/misc/LtTestNotVerb.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@

import com.jcabi.xml.XML;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.Collection;
import java.util.LinkedList;
Expand All @@ -36,6 +34,7 @@
import opennlp.tools.postag.POSModel;
import opennlp.tools.postag.POSTaggerME;
import org.cactoos.io.ResourceOf;
import org.cactoos.io.UncheckedInput;
import org.cactoos.list.ListOf;
import org.cactoos.text.TextOf;
import org.cactoos.text.UncheckedText;
Expand All @@ -49,11 +48,6 @@
* with POS tagging capabilities in order to determine the part of speech and
* tense for test object name.
* @since 0.0.22
* @todo #257:60min Configure model download only during the build and place into the JAR.
* Currently, we download model file each time when creating the lint, which may
* be slow in the usage of this lint. Instead, let's configure maven to download
* model file during the build, and place into JAR, so lint will be able to locate
* file from resources faster.
*/
public final class LtTestNotVerb implements Lint<XML> {

Expand Down Expand Up @@ -143,18 +137,14 @@ public String name() {
private static POSModel defaultPosModel() {
try {
return new POSModel(
new URI(
"https://opennlp.sourceforge.net/models-1.5/en-pos-perceptron.bin"
).toURL()
new UncheckedInput(
new ResourceOf("en-pos-perceptron.bin")
).stream()
);
} catch (final IOException exception) {
throw new IllegalStateException(
"Failed to read from I/O", exception
);
} catch (final URISyntaxException exception) {
throw new IllegalStateException(
"URI syntax is broken", exception
);
}
}
}
50 changes: 50 additions & 0 deletions src/test/java/org/eolang/lints/ModelExistsTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016-2025 Objectionary.com
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/

package org.eolang.lints;

import java.io.InputStream;
import org.cactoos.io.ResourceOf;
import org.eolang.lints.misc.LtTestNotVerb;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

/**
* Check that file with model for {@link LtTestNotVerb} exists on classpath.
*
* @since 0.0.38
*/
final class ModelExistsTest {
@Test
void testModelExists() {
Assertions.assertDoesNotThrow(
() -> {
final InputStream input = new ResourceOf("en-pos-perceptron.bin").stream();
input.readAllBytes();
Copy link
Member

@maxonfjvipon maxonfjvipon Feb 5, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Marat-Tim It's not a really good idea to test file presence by reading it. The file may be huge and your OS die. There is a special mechanism and method in Java to check the file presence

input.close();
},
"Exception is thrown when read from file"
);
}
}
Loading