Repository: scieloorg/xylose

Issue:
recuperação de DOI do documento.
Alguns DOI's estão registrados nas bases ISIS incluindo o domínio do crossref.

O Xylose deve remover qualquer conteúdo que não seja para do DOI.

ex:
http://www.crossref.org/10.1590/S2179-975X2012005000004
doi: 10.4322/actalb.02203010

O correto deve ser:
10.1590/S2179-975X2012005000004
10.4322/actalb.02203010



Discussion:

Patch:
diff --git a/setup.py b/setup.py
index e3f1883..0c97773 100755
--- a/setup.py
+++ b/setup.py
@@ -7,7 +7,7 @@ except ImportError:
 
 setup(
     name="xylose",
-    version='0.8b',
+    version='0.9b',
     description="A SciELO library to abstract a JSON data structure that is a product of the ISIS2JSON conversion using the ISIS2JSON type 3 data model.",
     author="SciELO",
     author_email="scielo-dev@googlegroups.com",
diff --git a/xylose/scielodocument.py b/xylose/scielodocument.py
index 39d94e3..8e5df08 100644
--- a/xylose/scielodocument.py
+++ b/xylose/scielodocument.py
@@ -27,6 +27,7 @@ else:
 
 LICENSE_REGEX = re.compile(r'a.+href="(.+)"')
 LICENSE_CREATIVE_COMMONS = re.compile(r'licenses/(.*)/.') # Extracts the creative commons id from the url.
+DOI_REGEX = re.compile(r'\d{2}\.\d+/.*$')
 
 def html_decode(string):
 
@@ -820,11 +821,22 @@ class Article(object):
         """
         This method retrieves the DOI of the given article, if it exists.
         """
+        raw_doi = None
+
         if 'doi' in self.data:
-            return self.data['doi']
+            raw_doi = self.data['doi']
 
         if 'v237' in self.data['article']:
-            return self.data['article']['v237'][0]['_']
+            raw_doi = self.data['article']['v237'][0]['_']
+
+
+        if not raw_doi:
+            return None
+
+        doi = DOI_REGEX.findall(raw_doi)
+
+        if len(doi) == 1:
+            return doi[0]
 
     @property
     def publisher_id(self):


Test patch:
diff --git a/tests/test_document.py b/tests/test_document.py
index a409140..4d0af56 100644
--- a/tests/test_document.py
+++ b/tests/test_document.py
@@ -1056,6 +1056,29 @@ class ArticleTests(unittest.TestCase):
 
         self.assertEqual(article.doi, u'10.1590/S2179-975X2012005000004')
 
+    def test_doi_v237(self):
+        article = self.article
+
+        article.data['article']['v237'] = [{'_': u'10.1590/S2179-975X2012005000004'}]
+
+        self.assertEqual(article.doi, u'10.1590/S2179-975X2012005000004')
+
+
+    def test_doi_clean_1(self):
+        article = self.article
+
+        article.data['doi'] = u'http://www.crossref.org/10.1590/S2179-975X2012005000004'
+
+        self.assertEqual(article.doi, u'10.1590/S2179-975X2012005000004')
+
+
+    def test_doi_clean_2(self):
+        article = self.article
+
+        article.data['doi'] = u'doi: 10.4322/actalb.02203010'
+
+        self.assertEqual(article.doi, u'10.4322/actalb.02203010')
+
     def test_without_doi(self):
         article = self.article