any23-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mosta...@apache.org
Subject svn commit: r1240571 - in /incubator/any23/trunk/core/src: main/java/org/apache/any23/extractor/rdfa/ test/java/org/apache/any23/ test/java/org/apache/any23/extractor/rdfa/ test/resources/html/rdfa/
Date Sat, 04 Feb 2012 18:08:55 GMT
Author: mostarda
Date: Sat Feb  4 18:08:54 2012
New Revision: 1240571

URL: http://svn.apache.org/viewvc?rev=1240571&view=rev
Log:
Fixed relative URIs management in RDFa11Parser.
Added strictest controls in RDFa11ExtractorTest (added verification of non blocking issues).
Fixed test files, added default namespace to be compliant to RDFa 1.1 specification.
This commit is related to issue #ANY23-42. 

Modified:
    incubator/any23/trunk/core/src/main/java/org/apache/any23/extractor/rdfa/RDFa11Parser.java
    incubator/any23/trunk/core/src/test/java/org/apache/any23/Any23Test.java
    incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/rdfa/RDFa11ExtractorTest.java
    incubator/any23/trunk/core/src/test/resources/html/rdfa/opengraph-structured-properties.html
    incubator/any23/trunk/core/src/test/resources/html/rdfa/rel-href.html
    incubator/any23/trunk/core/src/test/resources/html/rdfa/rel-rev.html
    incubator/any23/trunk/core/src/test/resources/html/rdfa/vocab.html

Modified: incubator/any23/trunk/core/src/main/java/org/apache/any23/extractor/rdfa/RDFa11Parser.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/core/src/main/java/org/apache/any23/extractor/rdfa/RDFa11Parser.java?rev=1240571&r1=1240570&r2=1240571&view=diff
==============================================================================
--- incubator/any23/trunk/core/src/main/java/org/apache/any23/extractor/rdfa/RDFa11Parser.java
(original)
+++ incubator/any23/trunk/core/src/main/java/org/apache/any23/extractor/rdfa/RDFa11Parser.java
Sat Feb  4 18:08:54 2012
@@ -345,7 +345,12 @@ public class RDFa11Parser {
      * @return
      */
     protected URI resolveURI(String uriStr) {
-        return RDFUtils.uri(uriStr);
+        return
+                isAbsoluteURI(uriStr)
+                        ?
+                RDFUtils.uri(uriStr)
+                        :
+                RDFUtils.uri( this.documentBase.toExternalForm(), uriStr );
     }
 
     /**
@@ -505,7 +510,7 @@ public class RDFa11Parser {
      * @param extractionResult
      */
     private void writeTriple(Resource s, URI p, Value o, ExtractionResult extractionResult)
{
-        if(logger.isTraceEnabled()) logger.trace(String.format("writeTriple(%s %s %s)" ,
s, p, o));
+        // if(logger.isTraceEnabled()) logger.trace(String.format("writeTriple(%s %s %s)"
, s, p, o));
         assert s != null : "subject   is null.";
         assert p != null : "predicate is null.";
         assert o != null : "object    is null.";
@@ -524,7 +529,7 @@ public class RDFa11Parser {
      */
     // TODO: add references to the RDFa 1.1 algorithm.
     private void processNode(Node currentElement, ExtractionResult extractionResult) throws
Exception {
-        if(logger.isTraceEnabled()) logger.trace("processNode(" + DomUtils.getXPathForNode(currentElement)
+ ")");
+        // if(logger.isTraceEnabled()) logger.trace("processNode(" + DomUtils.getXPathForNode(currentElement)
+ ")");
         final EvaluationContext currentEvaluationContext = getContext();
         try {
             if(
@@ -883,7 +888,7 @@ public class RDFa11Parser {
     }
 
     private void pushMappings(Node sourceNode, List<PrefixMap> prefixMapList) {
-        logger.trace("pushMappings()");
+        // logger.trace("pushMappings()");
 
         final Map<String, URI> mapping = new HashMap<String, URI>();
         for (PrefixMap prefixMap : prefixMapList) {
@@ -896,7 +901,7 @@ public class RDFa11Parser {
         if(uriMappingStack.isEmpty()) return;
         final URIMapping peek = uriMappingStack.peek();
         if( ! DomUtils.isAncestorOf(peek.sourceNode, node) ) {
-            logger.trace("popMappings()");
+            // logger.trace("popMappings()");
             uriMappingStack.pop();
         }
     }

Modified: incubator/any23/trunk/core/src/test/java/org/apache/any23/Any23Test.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/core/src/test/java/org/apache/any23/Any23Test.java?rev=1240571&r1=1240570&r2=1240571&view=diff
==============================================================================
--- incubator/any23/trunk/core/src/test/java/org/apache/any23/Any23Test.java (original)
+++ incubator/any23/trunk/core/src/test/java/org/apache/any23/Any23Test.java Sat Feb  4 18:08:54
2012
@@ -287,7 +287,7 @@ public class Any23Test extends Any23Onli
 
         final String bufferContent = byteArrayOutputStream.toString();
         logger.debug(bufferContent);
-        Assert.assertSame("Unexpected number of triples.", 42, StringUtils.countNL(bufferContent));
+        Assert.assertSame("Unexpected number of triples.", 65, StringUtils.countNL(bufferContent));
         
     }
 
@@ -321,8 +321,8 @@ public class Any23Test extends Any23Onli
     }
 
     @Test
-    public void testExtractionParameters() throws IOException, ExtractionException {
-        final int EXPECTED_TRIPLES  = 3;
+    public void testExtractionParameters() throws IOException, ExtractionException, TripleHandlerException
{
+        final int EXPECTED_TRIPLES  = 6;
         Any23 runner = new Any23();
         DocumentSource source = new FileDocumentSource(
                 new File("src/test/resources/org/apache/any23/validator/missing-og-namespace.html"),
@@ -336,15 +336,19 @@ public class Any23Test extends Any23Onli
         CompositeTripleHandler compositeTH1 = new CompositeTripleHandler();
         compositeTH1.addChild(cth1);
         compositeTH1.addChild(ctw1);
-        runner.extract(
-                new ExtractionParameters(
-                        DefaultConfiguration.singleton(),
-                        ValidationMode.None
-                ),
-                source,
-                compositeTH1
-        );
-        logger.debug(baos.toString());
+        try {
+            runner.extract(
+                    new ExtractionParameters(
+                            DefaultConfiguration.singleton(),
+                            ValidationMode.None
+                    ),
+                    source,
+                    compositeTH1
+            );
+        } finally {
+            compositeTH1.close();
+        }
+        logger.info(baos.toString());
         Assert.assertEquals("Unexpected number of triples.", EXPECTED_TRIPLES, cth1.getCount()
);
 
         baos.reset();
@@ -366,8 +370,9 @@ public class Any23Test extends Any23Onli
     }
 
     @Test
-    public void testExtractionParametersWithNestingDisabled() throws IOException, ExtractionException,
TripleHandlerException {
-        final int EXPECTED_TRIPLES = 20;
+    public void testExtractionParametersWithNestingDisabled()
+    throws IOException, ExtractionException, TripleHandlerException {
+        final int EXPECTED_TRIPLES = 21;
         Any23 runner = new Any23();
         DocumentSource source = new FileDocumentSource(
                 new File("src/test/resources/microformats/nested-microformats-a1.html"),

Modified: incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/rdfa/RDFa11ExtractorTest.java
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/rdfa/RDFa11ExtractorTest.java?rev=1240571&r1=1240570&r2=1240571&view=diff
==============================================================================
--- incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/rdfa/RDFa11ExtractorTest.java
(original)
+++ incubator/any23/trunk/core/src/test/java/org/apache/any23/extractor/rdfa/RDFa11ExtractorTest.java
Sat Feb  4 18:08:54 2012
@@ -48,7 +48,7 @@ public class RDFa11ExtractorTest extends
      */
     @Test
     public void testObjectResourceConversion() throws RepositoryException {
-        assertExtracts("html/rdfa/object-resource-test.html");
+        extractsAndCheckNoIssues("html/rdfa/object-resource-test.html");
         logger.debug(dumpModelToTurtle());
          assertContains(
                 null,
@@ -67,7 +67,7 @@ public class RDFa11ExtractorTest extends
      */
     @Test
     public void testExplicitDatatypeDeclaration() throws RepositoryException {
-        assertExtracts("html/rdfa/xmlliteral-datatype-test.html");
+        extractsAndCheckNoIssues("html/rdfa/xmlliteral-datatype-test.html");
         logger.debug(dumpModelToTurtle());
 
         Literal literal = RDFUtils.literal(
@@ -88,7 +88,7 @@ public class RDFa11ExtractorTest extends
      */
     @Test
     public void testRelWithHref() throws RepositoryException {
-         assertExtracts("html/rdfa/rel-href.html");
+        extractsAndCheckNoIssues("html/rdfa/rel-href.html");
         logger.debug(dumpModelToTurtle());
 
         assertContains(
@@ -110,7 +110,7 @@ public class RDFa11ExtractorTest extends
      */
     @Test
     public void testRelRevSupport() throws RepositoryException {
-        assertExtracts("html/rdfa/rel-rev.html");
+        extractsAndCheckNoIssues("html/rdfa/rel-rev.html");
         logger.debug(dumpModelToTurtle());
 
         assertContains(
@@ -132,7 +132,7 @@ public class RDFa11ExtractorTest extends
      */
     @Test
     public void testVocabSupport() throws RepositoryException {
-        assertExtracts("html/rdfa/vocab.html");
+        extractsAndCheckNoIssues("html/rdfa/vocab.html");
         logger.debug(dumpModelToTurtle());
 
         assertContains(
@@ -170,7 +170,7 @@ public class RDFa11ExtractorTest extends
     throws RepositoryException, RDFHandlerException, IOException, RDFParseException {
         final int EXPECTED_STATEMENTS = 33;
 
-        assertExtracts("html/rdfa/goodrelations-rdfa10.html");
+        extractsAndCheckNoIssues("html/rdfa/goodrelations-rdfa10.html");
         logger.debug(dumpModelToNQuads());
 
         Assert.assertEquals(EXPECTED_STATEMENTS, dumpAsListOfStatements().size());
@@ -191,7 +191,7 @@ public class RDFa11ExtractorTest extends
     throws RepositoryException, RDFHandlerException, IOException, RDFParseException {
         final int EXPECTED_STATEMENTS = 33;
 
-        assertExtracts("html/rdfa/goodrelations-rdfa11.html");
+        extractsAndCheckNoIssues("html/rdfa/goodrelations-rdfa11.html");
         logger.debug(dumpHumanReadableTriples());
 
         Assert.assertEquals(EXPECTED_STATEMENTS, dumpAsListOfStatements().size());
@@ -208,7 +208,7 @@ public class RDFa11ExtractorTest extends
      */
     @Test
     public void testOpenGraphStructuredProperties() throws IOException, ExtractionException,
RepositoryException {
-        assertExtracts("html/rdfa/opengraph-structured-properties.html");
+        extractsAndCheckNoIssues("html/rdfa/opengraph-structured-properties.html");
         logger.info( dumpHumanReadableTriples() );
 
         Assert.assertEquals(8, getStatementsSize(null, null, null) );
@@ -228,10 +228,15 @@ public class RDFa11ExtractorTest extends
         assertContains(baseURI, vOGP.siteName, RDFUtils.literal("IMDb") );
         assertContains(baseURI, vOGP.video, RDFUtils.literal("http://example.com/bond/trailer.swf")
);
     }
-
+    
     @Override
     protected ExtractorFactory<?> getExtractorFactory() {
         return RDFa11Extractor.factory;
     }
+    
+    private void extractsAndCheckNoIssues(String resource) {
+        assertExtracts(resource);
+        assertNoIssues();
+    }
 
 }

Modified: incubator/any23/trunk/core/src/test/resources/html/rdfa/opengraph-structured-properties.html
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/core/src/test/resources/html/rdfa/opengraph-structured-properties.html?rev=1240571&r1=1240570&r2=1240571&view=diff
==============================================================================
--- incubator/any23/trunk/core/src/test/resources/html/rdfa/opengraph-structured-properties.html
(original)
+++ incubator/any23/trunk/core/src/test/resources/html/rdfa/opengraph-structured-properties.html
Sat Feb  4 18:08:54 2012
@@ -1,4 +1,4 @@
-<html prefix="og: http://ogp.me/ns#">
+<html xmlns="http://www.w3.org/1999/xhtml" prefix="og: http://ogp.me/ns#">
 <head>
     <meta property="og:audio" content="http://example.com/bond/theme.mp3"/>
     <meta property="og:description"

Modified: incubator/any23/trunk/core/src/test/resources/html/rdfa/rel-href.html
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/core/src/test/resources/html/rdfa/rel-href.html?rev=1240571&r1=1240570&r2=1240571&view=diff
==============================================================================
--- incubator/any23/trunk/core/src/test/resources/html/rdfa/rel-href.html (original)
+++ incubator/any23/trunk/core/src/test/resources/html/rdfa/rel-href.html Sat Feb  4 18:08:54
2012
@@ -1,4 +1,4 @@
-<html>
+<html xmlns="http://www.w3.org/1999/xhtml">
 <head></head>
 <body>
 <div prefix="foaf:http://xmlns.com/foaf/0.1/" about="#me">

Modified: incubator/any23/trunk/core/src/test/resources/html/rdfa/rel-rev.html
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/core/src/test/resources/html/rdfa/rel-rev.html?rev=1240571&r1=1240570&r2=1240571&view=diff
==============================================================================
--- incubator/any23/trunk/core/src/test/resources/html/rdfa/rel-rev.html (original)
+++ incubator/any23/trunk/core/src/test/resources/html/rdfa/rel-rev.html Sat Feb  4 18:08:54
2012
@@ -1,4 +1,4 @@
-<html>
+<html xmlns="http://www.w3.org/1999/xhtml">
 <head></head>
 <body>
 As Gandalf the White said in

Modified: incubator/any23/trunk/core/src/test/resources/html/rdfa/vocab.html
URL: http://svn.apache.org/viewvc/incubator/any23/trunk/core/src/test/resources/html/rdfa/vocab.html?rev=1240571&r1=1240570&r2=1240571&view=diff
==============================================================================
--- incubator/any23/trunk/core/src/test/resources/html/rdfa/vocab.html (original)
+++ incubator/any23/trunk/core/src/test/resources/html/rdfa/vocab.html Sat Feb  4 18:08:54
2012
@@ -1,4 +1,4 @@
-<html>
+<html xmlns="http://www.w3.org/1999/xhtml">
 <head></head>
 <body>
 <div vocab="http://xmlns.com/foaf/0.1/" about="#me">



Mime
View raw message