@@ -36,9 +36,10 @@ public function convert( $arc2Triples, $arc2ResourceIndex, $arc2NSPrefixes ) {
3636 $ catPageTitle = $ uriToTitleConv ->convert ( $ triple ['o ' ] );
3737 $ catPageTitleWithNS = Title::makeTitleSafe ( NS_CATEGORY , $ catPageTitle )->getFullText ();
3838 // Add data for the subject page
39- $ this ->addDataToPage ( $ wikiPageTitle , $ triple ['s ' ], $ fact = null , $ catPageTitleWithNS );
39+ $ this ->addEquivUriToPage ( $ triple ['s ' ], $ wikiPageTitle );
40+ $ this ->addCategoryToPage ( $ catPageTitleWithNS , $ wikiPageTitle );
4041 // Add data for the category page
41- $ this ->addDataToPage ( $ catPageTitleWithNS , $ triple ['o ' ] );
42+ $ this ->addEquivUriToPage ( $ triple ['o ' ], $ catPageTitleWithNS );
4243
4344 } else if ( $ triple ['p ' ] === 'http://www.w3.org/2000/01/rdf-schema#subClassOf ' ) {
4445
@@ -48,18 +49,19 @@ public function convert( $arc2Triples, $arc2ResourceIndex, $arc2NSPrefixes ) {
4849 $ pageTitleWithNS = Title::makeTitleSafe ( NS_CATEGORY , $ wikiPageTitle )->getFullText ();
4950
5051 // Add data for the subject page
51- $ this ->addDataToPage ( $ pageTitleWithNS , $ triple ['s ' ], $ fact = null , $ catPageTitleWithNS );
52+ $ this ->addEquivUriToPage ( $ triple ['s ' ], $ pageTitleWithNS );
53+ $ this ->addCategoryToPage ( $ catPageTitleWithNS , $ pageTitleWithNS );
5254
5355 // Add data for the category page
54- $ this ->addDataToPage ( $ catPageTitleWithNS , $ triple ['o ' ] );
56+ $ this ->addEquivUriToPage ( $ triple ['o ' ], $ catPageTitleWithNS );
5557
5658 } else {
5759 // Separate handling for properties
5860 $ propertyTitle = $ uriToPropTitleConv ->convert ( $ triple ['p ' ] );
5961 // Add the property namespace to property title
6062 $ propTitleWithNS = Title::makeTitleSafe ( SMW_NS_PROPERTY , $ propertyTitle )->getFullText ();
6163 // Add Equivalent URI to property page
62- $ this ->addDataToPage ( $ propTitleWithNS , $ triple ['p ' ] );
64+ $ this ->addEquivUriToPage ( $ triple ['p ' ], $ propTitleWithNS );
6365
6466 /*
6567 * Decide whether to create a page for the linked "object" or not,
@@ -70,13 +72,13 @@ public function convert( $arc2Triples, $arc2ResourceIndex, $arc2NSPrefixes ) {
7072 case 'bnode ' :
7173 case 'uri ' :
7274 // Create new page for the object
73- $ object = $ uriToTitleConv ->convert ( $ triple ['o ' ] );
74- $ this ->addDataToPage ( $ object , $ triple ['o ' ] );
75+ $ objectTitleOrVal = $ uriToTitleConv ->convert ( $ triple ['o ' ] );
76+ $ this ->addEquivUriToPage ( $ triple ['o ' ], $ objectTitleOrVal );
7577 // Since URIs convert to pages, properties linking to URIs will be of 'Page' type
7678 $ propertyDataType = 'Page ' ;
7779 break ;
7880 case 'literal ' :
79- $ object = $ triple ['o ' ];
81+ $ objectTitleOrVal = $ triple ['o ' ];
8082
8183 // Determine data type of property
8284 $ xsd = 'http://www.w3.org/2001/XMLSchema# ' ;
@@ -116,7 +118,7 @@ public function convert( $arc2Triples, $arc2ResourceIndex, $arc2NSPrefixes ) {
116118 $ propertyDataType = 'URL ' ;
117119 break ;
118120 default :
119- if ( substr ( $ object , 0 , 4 ) === 'http ' ) {
121+ if ( substr ( $ objectTitleOrVal , 0 , 4 ) === 'http ' ) {
120122 $ propertyDataType = 'URL ' ;
121123 break ;
122124 }
@@ -131,46 +133,79 @@ public function convert( $arc2Triples, $arc2ResourceIndex, $arc2NSPrefixes ) {
131133 // NOTE: This is important to do BEFORE adding any fact using the property,
132134 // in order for the fact to get correct encoding in the ARC2 store.
133135 if ( !is_null ( $ propertyDataType ) ) {
134- $ this ->addDataToPage ( $ propTitleWithNS , null , null , null , $ propertyDataType );
136+ $ this ->addDataTypeToPage ( $ propertyDataType , $ propTitleWithNS );
135137 }
136138
137139 // Create a fact array
138- $ fact = array ( 'p ' => $ propertyTitle , 'o ' => $ object );
140+ $ fact = array ( 'p ' => $ propertyTitle , 'o ' => $ objectTitleOrVal );
139141 // Add data to class variables
140- $ this ->addDataToPage ( $ wikiPageTitle , $ triple ['s ' ], $ fact );
142+ $ this ->addEquivUriToPage ( $ triple ['s ' ], $ wikiPageTitle );
143+ $ this ->addFactToPage ( $ fact , $ wikiPageTitle );
141144 }
142145 }
143146
144147 return $ this ->wikiPages ;
145148 }
146149
150+
147151 /**
148- * Convenience function to add a $fact (predicate/object tuple) or $category into
149- * the RDFIOWikiPage according to the title specified in $pageTitle
150- * @param string $pageTitle
151152 * @param string $equivURI
152- * @param string $fact
153- * @param string $category
153+ * @param string $pageTitle
154154 */
155- private function addDataToPage ( $ pageTitle , $ equivURI = null , $ fact = null , $ category = null , $ dataType = null ) {
156- // Create page array if not exists in array
157- if ( !array_key_exists ( $ pageTitle , $ this ->wikiPages ) ) {
158- $ this ->wikiPages [$ pageTitle ] = new RDFIOWikiPage ( $ pageTitle );
159- }
155+ private function addEquivUriToPage ( $ equivURI , $ pageTitle ) {
160156 if ( !is_null ( $ equivURI ) ) {
161- $ this ->wikiPages [ $ pageTitle] ->addEquivalentURI ( $ equivURI );
157+ $ this ->getPage ( $ pageTitle ) ->addEquivalentURI ( $ equivURI );
162158 }
159+ }
160+
161+ /**
162+ * @param array $fact
163+ * @param string $pageTitle
164+ */
165+ private function addFactToPage ( $ fact , $ pageTitle ) {
163166 if ( !is_null ( $ fact ) ) {
164- $ this ->wikiPages [ $ pageTitle] ->addFact ( $ fact );
167+ $ this ->getPage ( $ pageTitle ) ->addFact ( $ fact );
165168 }
169+ }
170+
171+ /**
172+ * @param string $category
173+ * @param string $pageTitle
174+ */
175+ private function addCategoryToPage ( $ category , $ pageTitle ) {
166176 if ( !is_null ( $ category ) ) {
167- $ this ->wikiPages [ $ pageTitle] ->addCategory ( $ category );
177+ $ this ->getPage ( $ pageTitle ) ->addCategory ( $ category );
168178 }
179+ }
180+
181+ /**
182+ * @param string $dataType
183+ * @param string $pageTitle
184+ */
185+ private function addDataTypeToPage ( $ dataType , $ pageTitle ) {
169186 if ( !is_null ( $ dataType ) ) {
170- $ this ->wikiPages [$ pageTitle ]->addDataType ( $ dataType );
187+ $ this ->getPage ( $ pageTitle )->addDataType ( $ dataType );
188+ }
189+ }
190+
191+ /**
192+ * @param string $pageTitle
193+ */
194+ private function ensurePageExists ( $ pageTitle ) {
195+ // Create page array if not exists in array
196+ if ( !array_key_exists ( $ pageTitle , $ this ->wikiPages ) ) {
197+ $ this ->wikiPages [$ pageTitle ] = new RDFIOWikiPage ( $ pageTitle );
171198 }
172199 }
173200
201+ /**
202+ * @param string $pageTitle
203+ * @return RDFIOWikiPage $page
204+ */
205+ private function getPage ( $ pageTitle ) {
206+ $ this ->ensurePageExists ( $ pageTitle );
207+ return $ this ->wikiPages [$ pageTitle ];
208+ }
174209}
175210
176211class RDFIOARC2ToWikiConverterException extends MWException {
0 commit comments