diff --git a/README.md b/README.md index 5129ad7..52014aa 100644 --- a/README.md +++ b/README.md @@ -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? ========== diff --git a/src/main/java/widoco/Configuration.java b/src/main/java/widoco/Configuration.java index d6d058b..4efe4d8 100644 --- a/src/main/java/widoco/Configuration.java +++ b/src/main/java/widoco/Configuration.java @@ -28,7 +28,6 @@ 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; @@ -36,11 +35,7 @@ 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. @@ -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) @@ -192,20 +188,20 @@ private void initializeOntology(){ mainOntologyMetadata.setLatestVersion(""); mainOntologyMetadata.setRevision(""); mainOntologyMetadata.setPublisher(new Agent()); - mainOntologyMetadata.setImportedOntologies(new ArrayList()); - mainOntologyMetadata.setExtendedOntologies(new ArrayList()); + mainOntologyMetadata.setImportedOntologies(new ArrayList<>()); + mainOntologyMetadata.setExtendedOntologies(new ArrayList<>()); mainOntologyMetadata.setName(""); mainOntologyMetadata.setNamespacePrefix(""); License l = new License(); mainOntologyMetadata.setLicense(l); - mainOntologyMetadata.setSerializations(new HashMap()); + 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()); - mainOntologyMetadata.setContributors(new ArrayList()); + mainOntologyMetadata.setCreators(new ArrayList<>()); + mainOntologyMetadata.setContributors(new ArrayList<>()); mainOntologyMetadata.setCiteAs(""); mainOntologyMetadata.setDoi(""); mainOntologyMetadata.setStatus(""); @@ -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()); } @@ -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{ @@ -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; } diff --git a/src/main/java/widoco/Constants.java b/src/main/java/widoco/Constants.java index c7350df..0db193f 100644 --- a/src/main/java/widoco/Constants.java +++ b/src/main/java/widoco/Constants.java @@ -528,7 +528,11 @@ public static String getIndexDocument(String resourcesFolderName,Configuration c document += " Ontology Documentation generated by WIDOCO\n"; - + //Google analytics code + String analyticsCode = c.getGoogleAnalyticsCode(); + if(analyticsCode != null && !analyticsCode.isEmpty()){ + document += getAnalyticsCode(c.getGoogleAnalyticsCode()); + } //JSON-LD snippet document += getJSONLDSnippet(c); @@ -1078,4 +1082,16 @@ public static String getLegend(Properties lang){ ""; } + public static String getAnalyticsCode(String code){ + return "\n" + + "\n" + + ""; + } + } diff --git a/src/main/java/widoco/gui/GuiController.java b/src/main/java/widoco/gui/GuiController.java index 6363983..fe92eab 100644 --- a/src/main/java/widoco/gui/GuiController.java +++ b/src/main/java/widoco/gui/GuiController.java @@ -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){ @@ -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; @@ -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++; @@ -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) { diff --git a/src/main/java/widoco/gui/GuiStep3.form b/src/main/java/widoco/gui/GuiStep3.form index 2bc7afe..7e3c05d 100644 --- a/src/main/java/widoco/gui/GuiStep3.form +++ b/src/main/java/widoco/gui/GuiStep3.form @@ -203,22 +203,6 @@ - - - - - - - - - - - - - - - - @@ -251,15 +235,35 @@ - + + + + + + + + + + + + + + + + + + + + + - + @@ -317,6 +321,8 @@ + + @@ -475,6 +481,13 @@ + + + + + + + diff --git a/src/main/java/widoco/gui/GuiStep3.java b/src/main/java/widoco/gui/GuiStep3.java index 23d3684..559df85 100644 --- a/src/main/java/widoco/gui/GuiStep3.java +++ b/src/main/java/widoco/gui/GuiStep3.java @@ -78,6 +78,7 @@ private void initializeGUI(){ checkBoxHTAccess.setSelected(true); checkBoxWebVowl.setSelected(true); checkBoxAutomatedChangeLog.setSelected(true); + if(g.getConfig().getGoogleAnalyticsCode()!=null)analyticsField.setText(g.getConfig().getGoogleAnalyticsCode()); } /** This method is called from within the constructor to @@ -122,6 +123,8 @@ private void initComponents() { checkBoxHTAccess = new javax.swing.JCheckBox(); checkBoxWebVowl = new javax.swing.JCheckBox(); checkBoxAutomatedChangeLog = new javax.swing.JCheckBox(); + jLabel3 = new javax.swing.JLabel(); + analyticsField = new javax.swing.JTextField(); labelDescription = new javax.swing.JLabel(); widocoLogo = new javax.swing.JLabel(); jLabel2 = new javax.swing.JLabel(); @@ -264,6 +267,8 @@ public void mouseExited(java.awt.event.MouseEvent evt) { checkBoxAutomatedChangeLog.setText("Include change log from last version"); + jLabel3.setText("Google analytics code"); + javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1); jPanel1.setLayout(jPanel1Layout); jPanel1Layout.setHorizontalGroup( @@ -271,18 +276,6 @@ public void mouseExited(java.awt.event.MouseEvent evt) { .addGroup(jPanel1Layout.createSequentialGroup() .addContainerGap() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) - .addGroup(jPanel1Layout.createSequentialGroup() - .addComponent(addImportedOntologiesCheckBox) - .addGap(0, 0, Short.MAX_VALUE)) - .addComponent(checkBoxHTAccess, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addComponent(checkBoxProv, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() - .addComponent(checkBoxWebVowl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) - .addGap(219, 219, 219)) - .addComponent(checkBoxAutomatedChangeLog, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) - .addGap(104, 104, 104)) .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(checkBoxRefs) @@ -308,14 +301,30 @@ public void mouseExited(java.awt.event.MouseEvent evt) { .addGroup(jPanel1Layout.createSequentialGroup() .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) .addComponent(includeAnnProps) - .addComponent(includeIndividuals) + .addComponent(includeIndividuals)) + .addGap(0, 0, Short.MAX_VALUE)) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() + .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) .addGroup(jPanel1Layout.createSequentialGroup() .addComponent(jLabel1) .addGap(18, 18, 18) .addComponent(w3C) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) - .addComponent(customRadioButton))) - .addGap(0, 0, Short.MAX_VALUE)))) + .addComponent(customRadioButton) + .addGap(18, 18, 18) + .addComponent(jLabel3) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) + .addComponent(analyticsField)) + .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup() + .addComponent(addImportedOntologiesCheckBox) + .addGap(0, 0, Short.MAX_VALUE)) + .addComponent(checkBoxHTAccess, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addComponent(checkBoxProv, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGroup(jPanel1Layout.createSequentialGroup() + .addComponent(checkBoxWebVowl, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + .addGap(219, 219, 219)) + .addComponent(checkBoxAutomatedChangeLog, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) + .addGap(104, 104, 104)))) ); jPanel1Layout.setVerticalGroup( jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) @@ -361,7 +370,9 @@ public void mouseExited(java.awt.event.MouseEvent evt) { .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) .addComponent(w3C) .addComponent(customRadioButton) - .addComponent(jLabel1)) + .addComponent(jLabel1) + .addComponent(jLabel3) + .addComponent(analyticsField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) .addGap(10, 10, 10)) ); @@ -491,6 +502,7 @@ private void saveState(){ g.getConfig().setCreateHTACCESS(checkBoxHTAccess.isSelected()); g.getConfig().setCreateWebVowlVisualization(checkBoxWebVowl.isSelected()); g.getConfig().setIncludeChangeLog(checkBoxAutomatedChangeLog.isSelected()); + g.getConfig().setGoogleAnalyticsCode(analyticsField.getText()); } private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing @@ -580,6 +592,7 @@ private String loadSection(){ // Variables declaration - do not modify//GEN-BEGIN:variables private javax.swing.JButton abstractSectionButton; private javax.swing.JCheckBox addImportedOntologiesCheckBox; + private javax.swing.JTextField analyticsField; private javax.swing.JButton backButton; private javax.swing.JProgressBar barStatus; private javax.swing.ButtonGroup buttonGroup1; @@ -600,6 +613,7 @@ private String loadSection(){ private javax.swing.JButton introductionSectionButton; private javax.swing.JLabel jLabel1; private javax.swing.JLabel jLabel2; + private javax.swing.JLabel jLabel3; private javax.swing.JPanel jPanel1; private javax.swing.JScrollPane jScrollPane1; private javax.swing.JSeparator jSeparator1;