Skip to content

Commit

Permalink
Merge pull request #289 from dgarijo/develop
Browse files Browse the repository at this point in the history
Fix #100
  • Loading branch information
dgarijo authored Jun 4, 2018
2 parents 2e9ad1f + 8295533 commit f72fa4b
Show file tree
Hide file tree
Showing 6 changed files with 106 additions and 183 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,11 @@ The `-webVowl` flag provides a link to a visualization based on WebVowl (http://

The `-licensius` flag uses the Licensius web services (http://licensius.com/apidoc/index.html) to retrieve license metadata. Only works if the `-getOntologyMetadata` flag is enabled.

The `-ignoreIndividuals` allows you to ignore the named individuals in the ontology.
The `-ignoreIndividuals` flag allows you to ignore the named individuals in the ontology.

The `-includeAnnotationProperties` will include annotation properties defined in your ontology (by default they are not included)
The `-includeAnnotationProperties` flag will include annotation properties defined in your ontology (by default they are not included)

The `-analytics` flag will add a code snippet for Google analytics to track your page. You need to add your code next to it. For example: UA-1234

How can I make WIDOCO automatically recognize my vocabulary annotations?
==========
Expand Down
160 changes: 15 additions & 145 deletions src/main/java/widoco/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,14 @@
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import java.util.stream.Collectors;
import javax.imageio.ImageIO;
import org.semanticweb.owlapi.model.OWLOntology;
import widoco.entities.Agent;
import widoco.entities.License;
import widoco.entities.Ontology;
import widoco.gui.GuiController;
import licensius.GetLicense;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLAnnotation;
import org.semanticweb.owlapi.model.OWLAnnotationSubject;
import org.semanticweb.owlapi.model.OWLEntity;
import org.semanticweb.owlapi.search.EntitySearcher;

/**
* class for storing all the details to generate the ontology.
Expand Down Expand Up @@ -83,6 +78,7 @@ public class Configuration {
private String overviewPath;
private String descriptionPath;
private String referencesPath;
private String googleAnalyticsCode = null;

/**
* Property for including an ontology diagram (future work)
Expand Down Expand Up @@ -192,20 +188,20 @@ private void initializeOntology(){
mainOntologyMetadata.setLatestVersion("");
mainOntologyMetadata.setRevision("");
mainOntologyMetadata.setPublisher(new Agent());
mainOntologyMetadata.setImportedOntologies(new ArrayList<Ontology>());
mainOntologyMetadata.setExtendedOntologies(new ArrayList<Ontology>());
mainOntologyMetadata.setImportedOntologies(new ArrayList<>());
mainOntologyMetadata.setExtendedOntologies(new ArrayList<>());
mainOntologyMetadata.setName("");
mainOntologyMetadata.setNamespacePrefix("");
License l = new License();
mainOntologyMetadata.setLicense(l);
mainOntologyMetadata.setSerializations(new HashMap<String, String>());
mainOntologyMetadata.setSerializations(new HashMap<>());
//add default serializations: rdf/xml, n3, turtle and json-ld
mainOntologyMetadata.addSerialization("RDF/XML", "ontology.xml");
mainOntologyMetadata.addSerialization("TTL", "ontology.ttl");
mainOntologyMetadata.addSerialization("N-Triples", "ontology.nt");
mainOntologyMetadata.addSerialization("JSON-LD", "ontology.json");
mainOntologyMetadata.setCreators(new ArrayList<Agent>());
mainOntologyMetadata.setContributors(new ArrayList<Agent>());
mainOntologyMetadata.setCreators(new ArrayList<>());
mainOntologyMetadata.setContributors(new ArrayList<>());
mainOntologyMetadata.setCiteAs("");
mainOntologyMetadata.setDoi("");
mainOntologyMetadata.setStatus("");
Expand Down Expand Up @@ -351,6 +347,7 @@ private void loadPropertyFile(String path){
if(!"".equals(serializationJSONLD)){
mainOntologyMetadata.addSerialization("JSON-LD", serializationJSONLD);
}
this.googleAnalyticsCode = propertyFile.getProperty("GoogleAnalyticsCode");
} catch (Exception ex) {
System.err.println("Error while reading configuration properties "+ex.getMessage());
}
Expand Down Expand Up @@ -563,141 +560,6 @@ private void completeMetadata(OWLAnnotation a){
break;
}
}
// public void loadPropertiesFromOntology(OntModel m){
// //maybe there are some properties regarding the version of the uri that I am missing...
// if(m == null){
// System.err.println("The ontology could not be read...");
// return;
// }
// initializeOntology();
// this.mainOntologyMetadata.setName("[Ontology Name]");
// this.mainOntologyMetadata.setNamespacePrefix("[Ontology NS Prefix]");
// this.mainOntologyMetadata.setNamespaceURI("[Ontology URI]");
// //we assume only one ontology per file.
// try{
// OntResource onto = m.getOntClass("http://www.w3.org/2002/07/owl#Ontology").listInstances().next();
// this.mainOntologyMetadata.setNamespaceURI(onto.getURI());
// this.mainOntologyMetadata.setName(onto.getLocalName());
// Iterator it = onto.listProperties();
// String propertyName, value;
// while(it.hasNext()){
// Statement s = (Statement) it.next();
// propertyName = s.getPredicate().getLocalName();
// try{
// value = s.getObject().asLiteral().getString();
// }catch(Exception e){
// value = s.getObject().asResource().getURI();
// }
// // System.out.println(propertyName + " " + value);
// // fill in the properties here.
// if(propertyName.equals("label")){
// this.mainOntologyMetadata.setName(value);
// }else
// if(propertyName.equals("abstract")){
// this.abstractSection = value;
// }else
// if(propertyName.equals("title")){
// mainOntologyMetadata.setTitle(value);
// }else
// if(propertyName.equals("replaces")||propertyName.equals("wasRevisionOf")||propertyName.equals("priorVersion")){
// mainOntologyMetadata.setPreviousVersion(value);
// }else
// if(propertyName.equals("versionInfo")){
// mainOntologyMetadata.setRevision(value);
// }else
// if(propertyName.equals("versionIRI")){
// mainOntologyMetadata.setThisVersion(value);
// }else
// if(propertyName.equals("preferredNamespacePrefix")){
// this.mainOntologyMetadata.setNamespacePrefix(value);
// }else
// if(propertyName.equals("preferredNamespaceUri")){
// this.mainOntologyMetadata.setNamespaceURI(value);
// }else
// //we deal with the license by invoking the licensius service
// //(only if we cannot find it)
// if(propertyName.equals("license")){
// License l = new License();
// if(isURL(value)){
// l.setUrl(value);
// }else{
// l.setName(value);
// }
// mainOntologyMetadata.setLicense(l);
// }else
// if(propertyName.equals("creator")||propertyName.equals("contributor")
// ||propertyName.equals("publisher")){
// Agent g = new Agent();
// if(isURL(value)){
// g.setURL(value);
// g.setName(value);
// }else{
// g.setName(value);
// g.setURL("");
// }
// if(propertyName.equals("creator")){
// mainOntologyMetadata.getCreators().add(g);
// }else if (propertyName.equals("contributor")){
// mainOntologyMetadata.getContributors().add(g);
// }else{
// mainOntologyMetadata.setPublisher(g);
// }
// }else
// if(propertyName.equals("created")){
// if(mainOntologyMetadata.getReleaseDate()==null || "".equals(mainOntologyMetadata.getReleaseDate())){
// mainOntologyMetadata.setReleaseDate(value);
// }
// }else
// if(propertyName.equals("modified")){
// mainOntologyMetadata.setReleaseDate(value);
// }else
// if(propertyName.equals("bibliographicCitation")){
// mainOntologyMetadata.setCiteAs(value);
// }else
// if(propertyName.equals("doi")||propertyName.equals("hasDOI")){
// mainOntologyMetadata.setDoi(value);
// }else
// if(propertyName.equals("backwardsCompatibleWith")){
// mainOntologyMetadata.setBackwardsCompatibleWith(value);
// }else
// if(propertyName.equals("status")){
// mainOntologyMetadata.setStatus(value);
// }else
// if(propertyName.equals("imports")){
// Ontology o = new Ontology();
// if(isURL(value)){
// o.setNamespaceURI(value);
// o.setName(value);
// }else{
// o.setName(value);
// o.setNamespaceURI("");
// }
// mainOntologyMetadata.getImportedOntologies().add(o);
// }
// //to do: if property is comment and abstract is null, then complete abstract.
// }
// if(this.mainOntologyMetadata.getName()==null || this.mainOntologyMetadata.getName().equals("")){
// this.mainOntologyMetadata.setName(mainOntologyMetadata.getTitle());
// }
// if(mainOntologyMetadata.getStatus()==null || mainOntologyMetadata.getStatus().equals("")){
// mainOntologyMetadata.setStatus("Ontology Specification Draft");
// }
// }catch(Exception e){
// System.err.println("No ontology declared. Ignoring properties");
// }
// if(isUseLicensius()){
// String licName;
// String lic = GetLicense.getFirstLicenseFound(mainOntologyMetadata.getNamespaceURI());
// if (!lic.isEmpty()&& !lic.equals("unknown"))
// {
// mainOntologyMetadata.getLicense().setUrl(lic);
// licName = GetLicense.getTitle(lic);
// mainOntologyMetadata.getLicense().setName(licName);
// }
// }
//
// System.out.println("Loaded properties from ontology");
// }

private boolean isURL(String s){
try{
Expand All @@ -711,6 +573,14 @@ private boolean isURL(String s){
}
}

public String getGoogleAnalyticsCode() {
return googleAnalyticsCode;
}

public void setGoogleAnalyticsCode(String googleAnalyticsCode) {
this.googleAnalyticsCode = googleAnalyticsCode;
}

public void setOverwriteAll(boolean s){
this.overwriteAll = s;
}
Expand Down
18 changes: 17 additions & 1 deletion src/main/java/widoco/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,11 @@ public static String getIndexDocument(String resourcesFolderName,Configuration c
document += " <title>Ontology Documentation generated by WIDOCO</title>\n";



//Google analytics code
String analyticsCode = c.getGoogleAnalyticsCode();
if(analyticsCode != null && !analyticsCode.isEmpty()){
document += getAnalyticsCode(c.getGoogleAnalyticsCode());
}

//JSON-LD snippet
document += getJSONLDSnippet(c);
Expand Down Expand Up @@ -1078,4 +1082,16 @@ public static String getLegend(Properties lang){
"</div>";
}

public static String getAnalyticsCode(String code){
return "<!-- Global site tag (gtag.js) - Google Analytics -->\n" +
"<script async src=\"https://www.googletagmanager.com/gtag/js?id="+code+"\"></script>\n" +
"<script>\n" +
" window.dataLayer = window.dataLayer || [];\n" +
" function gtag(){dataLayer.push(arguments);}\n" +
" gtag('js', new Date());\n" +
"\n" +
" gtag('config', '"+code+"');\n" +
"</script>";
}

}
10 changes: 9 additions & 1 deletion src/main/java/widoco/gui/GuiController.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public GuiController(String[] args){
includeImportedOntologies = false, htAccess = false, webVowl=false, errors = false, licensius = false,
generateOnlyCrossRef = false, includeNamedIndividuals=true, includeAnnotationProperties = false;
String confPath="";
String code=null;//for tracking analytics.
String[] languages = null;
int i=0;
while(i< args.length){
Expand Down Expand Up @@ -125,6 +126,10 @@ public GuiController(String[] args){
languages = args[i+1].replace(" ","").split("-");
i++;
break;
case "-analytics":
code = args[i+1];
i++;
break;
case "-webVowl":
webVowl = true;
break;
Expand All @@ -139,7 +144,7 @@ public GuiController(String[] args){
break;
default:
System.out.println("Command"+s+" not recognized.");
System.out.println("Usage: java -jar widoco.jar [-ontFile file] or [-ontURI uri] [-outFolder folderName] [-confFile propertiesFile] [-getOntologyMetadata] [-oops] [-rewriteAll] [-crossRef] [-saveConfig configOutFile] [-lang lang1-lang2] [-includeImportedOntologies] [-htaccess] [-licensius] [-webVowl] [-ignoreIndividuals] [-includeAnnotationProperties]\n");
System.out.println("Usage: java -jar widoco.jar [-ontFile file] or [-ontURI uri] [-outFolder folderName] [-confFile propertiesFile] [-getOntologyMetadata] [-oops] [-rewriteAll] [-crossRef] [-saveConfig configOutFile] [-lang lang1-lang2] [-includeImportedOntologies] [-htaccess] [-licensius] [-webVowl] [-ignoreIndividuals] [-includeAnnotationProperties] [-analytics analyticsCode]\n");
return;
}
i++;
Expand Down Expand Up @@ -174,6 +179,9 @@ public GuiController(String[] args){
this.config.setUseLicensius(licensius);
this.config.setIncludeNamedIndividuals(includeNamedIndividuals);
this.config.setIncludeAnnotationProperties(includeAnnotationProperties);
if(code!=null){
this.config.setGoogleAnalyticsCode(code);
}
if(languages!=null){
config.removeLanguageToGenerate("en");//default
for (String language : languages) {
Expand Down
Loading

0 comments on commit f72fa4b

Please sign in to comment.