Skip to content

Commit

Permalink
Algorithm generation doc + version 1.1
Browse files Browse the repository at this point in the history
  • Loading branch information
tfrancart committed Jul 9, 2020
1 parent 4f579c8 commit d85c52f
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 6 deletions.
4 changes: 2 additions & 2 deletions issnbot-app/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.issn</groupId>
<artifactId>issnbot-root-pom</artifactId>
<version>1.0</version>
<version>1.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -133,7 +133,7 @@
<dependency>
<groupId>org.issn</groupId>
<artifactId>issnbot-lib</artifactId>
<version>1.0</version>
<version>1.1</version>
</dependency>

</dependencies>
Expand Down
2 changes: 1 addition & 1 deletion issnbot-lib/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<parent>
<groupId>org.issn</groupId>
<artifactId>issnbot-root-pom</artifactId>
<version>1.0</version>
<version>1.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ public List<Statement> updateOfficialWebsiteStatements(SerialEntry serial)
@Description(
title = "ISSN-L (P7363)",
definition=
"The ISSN-L processing is relatively straightforward because it does not hold the ISSN reference (being an identifier):\n"
"The ISSN-L processing is relatively straightforward because it does not hold the ISSN reference (being an identifier), like title, language etc.:\n"
+ "- If multiple ISSN-L are found on the same item, this is not a situation we can deal with, so this is considered an error.\n"
+ "- If an ISSN-L statement with the same value does not exist, then:\n"
+ " - Create a new ISSN-L statement on the item, without any reference.\n",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package org.issn.issnbot.doc;

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import org.apache.commons.io.FileUtils;
import org.issn.issnbot.WikidataSerial;

public class AlgorithmDocumentationGenerator {

public static void main(String[] args) throws IOException {
File outputFile = new File(args[0]);
StringBuffer sb = new StringBuffer();
sb.append("# ISSNBot update algorithm"+"\n");
sb.append("_note : this file is automatically generated from the documentation in `WikidataSerial.java`._"+"\n");
sb.append("\n");
sb.append("This is the algorithms ISSNBot uses to update Wikidata. They are applied in the order listed here."+"\n");
sb.append("\n");

Method[] methods = WikidataSerial.class.getMethods();
List<Description> descriptions = new ArrayList<>();
for (Method m : methods) {
Description d = m.getAnnotation(Description.class);
if(d != null) {
descriptions.add(d);
}
}

// sort based on order
Collections.sort(descriptions, (d1, d2) -> d1.order() - d2.order());

for (Description description : descriptions) {
sb.append("## "+description.title()+"\n");
sb.append("\n");
sb.append(description.definition()+"\n");
sb.append("\n");
}

FileUtils.write(outputFile, sb.toString(), "UTF-8");
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package org.issn.issnbot.doc;

import static java.lang.annotation.ElementType.FIELD;
import static java.lang.annotation.ElementType.METHOD;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

@Retention(RetentionPolicy.RUNTIME)
@Target(FIELD)
@Target({ FIELD, METHOD })
public @interface Description {
public String definition();
public String title() default "";
public int order() default 0;
}
14 changes: 13 additions & 1 deletion issnbot-release/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<parent>
<groupId>org.issn</groupId>
<artifactId>issnbot-root-pom</artifactId>
<version>1.0</version>
<version>1.1</version>
<relativePath>../pom.xml</relativePath>
</parent>

Expand Down Expand Up @@ -57,8 +57,20 @@
<arguments>${project.basedir}/src/main/resources/UpdateStatuses.md</arguments>
</configuration>
</execution>
<execution>
<id>generate-algorithms-documentation</id>
<phase>generate-resources</phase>
<goals>
<goal>java</goal>
</goals>
<configuration>
<mainClass>org.issn.issnbot.doc.AlgorithmDocumentationGenerator</mainClass>
<arguments>${project.basedir}/src/main/resources/UpdateAlgorithms.md</arguments>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>

Expand Down

0 comments on commit d85c52f

Please sign in to comment.