Пример #1
0
        public void BeforeSemanticOperationTest()// throws SIMPLTranslationException
        {
            // test FilterLocation.paramOps & alternativeHosts
            String url1 = "http://dl.acm.org/citation.cfm?id=2063231.2063237&coll=DL";

            // test FilterLocation.stripPrefix
            String url2 = "http://www.amazon.co.uk/gp/bestsellers/books/515344/ref=123";

            // test FilterLocation.Regex
            // added in file products.xml in meta_metadata name="amazon_bestseller_list":
            // <before_semantic_actions>
            //  <filter_location>
            //   <regex match="http://([w]+)\.amazon\.com/gp" replace="http://t$1.gstatic.com/images" />
            //  </filter_location>
            // </before_semantic_actions>
            String url3 = "http://www.amazon.com/gp/bestsellers/books/6";

            SimplTypesScope _repositoryMetadataTranslationScope = RepositoryMetadataTranslationScope.Get();

            SemanticsGlobalScope _semanticsSessionScope = new SemanticsSessionScope(
                _repositoryMetadataTranslationScope,
                MetaMetadataRepositoryInit.DEFAULT_REPOSITORY_LOCATION);

            Document metadata = _semanticsSessionScope.GetOrConstructDocument(new ParsedUri(url1));

            MetaMetadata metaMetadata = (MetaMetadata)metadata.MetaMetadata;

            SemanticOperationHandler handler = new SemanticOperationHandler(_semanticsSessionScope, null);

            handler.TakeSemanticOperations(metaMetadata, metadata, metaMetadata.BeforeSemanticActions);
        }
        public static string GetJsonMMD(MetaMetadata mmd)
        {
            if (mmd == null)
            {
                return(null);
            }

            string result = null;

            lock (mmdJSONCache)
            {
                mmdJSONCache.TryGetValue(mmd, out result);
            }
            if (result == null)
            {
                StringBuilder mmdJSON = new StringBuilder();
                mmdJSON.Append("mmd = ");
                mmdJSON.Append(SimplTypesScope.Serialize(mmd, StringFormat.Json));
                mmdJSON.Append(";");
                result = mmdJSON.ToString();
                lock (mmdJSONCache)
                {
                    mmdJSONCache.Add(mmd, result);
                }
            }
            return(result);
        }
Пример #3
0
        public override Object Perform(Object obj)    // throws IOException
        {
            RichDocument doc = (RichDocument)obj;
            MetaMetadata mmd = (MetaMetadata)doc.MetaMetadata;

/*		    Dictionary<MetaMetadataSelector, MetaMetadata> reselectMap = mmd.ReselectMap;
 *                  if (reselectMap != null)
 *                  {
 *                          foreach (MetaMetadataSelector selector in reselectMap.Keys)
 *                          {
 *                                  if (selector.reselect(doc))
 *                                  {
 *                                          MetaMetadata newMmd = reselectMap[selector];
 *                                          DocumentParser newParser = DocumentParser.get(newMmd, sessionScope);
 *                                          newParser.fillValues(documentParser.purlConnection(), doc.getOrConstructClosure(), sessionScope);
 *                                          if (documentParser instanceof ParserBase && newParser instanceof ParserBase)
 *                                          {
 *                                                  CompoundDocument newDoc = (CompoundDocument) newMmd.constructMetadata();
 *                                                  newDoc.setLocation(doc.getLocation());
 *                                                  ParserBase newParserBase = (ParserBase) newParser;
 *                                                  org.w3c.dom.Document dom = ((ParserBase) documentParser).getDom();
 *                                                  newParserBase.parse(newDoc, newMmd, dom);
 *
 *                                                  DocumentClosure closure = doc.getOrConstructClosure();
 *                                                  closure.changeDocument(newDoc);
 *
 *                                                  return newDoc;
 *                                          }
 *                                  }
 *                          }
 *                  }*/
            return(null);
        }
        private void WebView_LoadCompleted(object sender, EventArgs e)
        {
            //if (Source == null || BLANK_PAGE.Equals(Source))// || loadingComplete)
            //   return;
            WebView webView = sender as WebView;

            if (webView == null)
            {
                return;
            }
            webView.Stop(); // Stopping further requests.
            Console.WriteLine("Finished loading in " + DateTime.Now.Subtract(timeStart).TotalMilliseconds + "ms. Executing javascript. -- ");
            Console.WriteLine("======================================= Time To Load : " + DateTime.Now.Subtract(timeStart).TotalMilliseconds);
            parseStart = DateTime.Now;
            MetaMetadataRepository repository = SemanticsSessionScope.MetaMetadataRepository;
            MetaMetadata           mmd        = repository.GetDocumentMM(_puri);

            Console.WriteLine("Got MMD: " + mmd.Name);
            String jsonMMD = WebBrowserPool.GetJsonMMD(mmd);

            //Console.WriteLine("json:\n" + jsonMMD + "\n");
            //jsonMMD = jsonMMD.Replace("\\", "\\\\");

            webView.JSConsoleMessageAdded += new JSConsoleMessageAddedEventHandler(JSConsoleEvent);

            webView.ExecuteJavascript(jsonMMD);
            webView.ExecuteJavascript(WebBrowserPool.MmdDomHelperJsString);
            Console.WriteLine("Done js code execution, calling function. --" + DateTime.Now + " : " + DateTime.Now.Millisecond);
            //TODO: Currently executes asynchronously. Can we make this asynchronous?

            webView.CreateObject("CallBack");
            webView.SetObjectCallback("CallBack", "MetadataExtracted", OnMetadataExtracted);

            //webView.ExecuteJavascript("CallBack.MetadataExtracted('some value');");
            //Return happens through the task, on completion of the method via the callback
            webView.ExecuteJavascript("extractMetadataWithCallback(mmd);");

            _requestTimedOut.Start();
        }
Пример #5
0
        public void TakeSemanticOperations(MetaMetadata metaMetadata, Metadata metadata, List <SemanticOperation> semanticActions)
        {
            if (semanticActions == null)
            {
                Debug.WriteLine("warning: no semantic actions exist");
                return;
            }

            if (requestWaiting)
            {
                requestWaiting = false;
            }
            else
            {
                this.metaMetadata = metaMetadata;
                this.metadata     = metadata;

                //FIXME -- should not have SemanticOperationsKeyWords && SemanticOperationsNamedArguments as separate sets !!!
                semanticOperationVariableMap.Put(DocumentType, documentParser);
                semanticOperationVariableMap.Put(SemanticOperationKeyWords.Metadata, metadata);
//edit			    semanticOperationVariableMap.Add(TRUE_PURL, documentParser.getTruePURL());

                PreSemanticOperationsHook(metadata);
            }
            for (int i = 0; i < semanticActions.Count; i++)
            {
                SemanticOperation action = semanticActions[i];
                HandleSemanticOperation(action, documentParser, semanticsScope);
                if (requestWaiting)
                {
                    return;
                }
            }
            PostSemanticOperationsHook(metadata);

            Recycle();
        }
        public static string GetJsonMMD(MetaMetadata mmd)
        {
            if (mmd == null)
                return null;

            string result = null;
            lock (mmdJSONCache)
            {
                mmdJSONCache.TryGetValue(mmd, out result);
            }
            if (result == null)
            {
                StringBuilder mmdJSON = new StringBuilder();
                mmdJSON.Append("mmd = ");
                mmdJSON.Append(SimplTypesScope.Serialize(mmd, StringFormat.Json));
                mmdJSON.Append(";");
                result = mmdJSON.ToString();
                lock (mmdJSONCache)
                {
                    mmdJSONCache.Add(mmd, result);
                }
            }
            return result;
        }
Пример #7
0
        public void SemanticOperationTest()// throws SIMPLTranslationException
        {
            String collectedExampleUrlMetadata         = @"..\..\..\..\..\MetaMetadataRepository\MmdRepository\testData\collectedExampleUrlMetadata.xml";
            String collectedExampleUrlMetadataNoAuthor = @"..\..\Data\InformationCompositionDeclarationExample.xml";
            String useAuthor = @"..\..\Data\InformationCompositionDeclarationUseAuthor.xml";

            SimplTypesScope _repositoryMetadataTranslationScope = RepositoryMetadataTranslationScope.Get();

            SemanticsGlobalScope _semanticsSessionScope = new SemanticsSessionScope(
                _repositoryMetadataTranslationScope,
                MetaMetadataRepositoryInit.DEFAULT_REPOSITORY_LOCATION);

            InformationCompositionDeclaration doc = (InformationCompositionDeclaration)_repositoryMetadataTranslationScope.DeserializeFile(collectedExampleUrlMetadata, Format.Xml);

            foreach (Metadata metadata in doc.Metadata)
            {
                MetaMetadata metaMetadata = (MetaMetadata)metadata.MetaMetadata;

                SemanticOperationHandler handler = new SemanticOperationHandler(_semanticsSessionScope, null);
                handler.TakeSemanticOperations(metaMetadata, metadata, metaMetadata.SemanticActions);
            }

            Console.WriteLine(SimplTypesScope.Serialize(doc, StringFormat.Xml));
        }
/*        public override Object Perform(Object obj)
 *      {
 *          return null;
 *      }
 */
        public override Object Perform(Object obj)
        {
            Document source = ResolveSourceDocument();

            Image image = (Image)GetArgumentObject(SemanticOperationNamedArguments.Metadata);

            if (image == null)
            {
                ParsedUri imagePURL = (ParsedUri)GetArgumentObject(SemanticOperationNamedArguments.ImagePurl);

/*			    if (imagePURL != null)
 *                          {
 *                                  image								= sessionScope.GetOrConstructImage(imagePURL);
 *
 *                                  //TODO -- if it already exists: (1) do we need to download??
 *                                  //															(2) should we merge metadata
 *                          }
 */
            }
            else
            {
                //TODO add to global collections?! if already there merge!
            }
            if (image != null && image.Location != null)
            {
                image.SemanticsSessionScope = sessionScope as SemanticsSessionScope;

                Document mixin = (Document)GetArgumentObject(SemanticOperationNamedArguments.Mixin);
                if (mixin != null)
                {
                    image.AddMixin(mixin);
                }

                Object captionObject = GetArgumentObject(SemanticOperationNamedArguments.Caption);
                String caption       = (captionObject != null) ? captionObject.ToString() : null;

                int width  = GetArgumentInteger(SemanticOperationNamedArguments.Width, 0);
                int height = GetArgumentInteger(SemanticOperationNamedArguments.Height, 0);

                ParsedUri hrefPURL = (ParsedUri)GetArgumentObject(SemanticOperationNamedArguments.Href);
                Document  outlink  = (Document)GetArgumentObject(SemanticOperationNamedArguments.HrefMetadata);
                //if (hrefPURL != null & outlink == null)
                //	    outlink				= sessionScope.GetOrConstructDocument(hrefPURL);

                ImageClipping imageClipping = image.ConstructClipping(source, outlink, caption, null);
                source.AddClipping(imageClipping);

                DocumentClosure imageClosure;

                if (this.sessionScope is SemanticsSessionScope)
                {
                    imageClosure = image.GetOrConstructClosure();

                    if (documentParser != null)
                    {
                    }
                    else
                    {
                        //imageClosure.RequestMetadata();
                    }
                }
                else
                {
                    image.GetOrConstructClosure();
                }

                return(image);
            }
            else
            {
                MetaMetadata mm       = GetMetaMetadata();
                String       mmString = mm != null ? mm.Name : "Couldn't getMetaMetadata()";
                Debug.WriteLine("Can't createAndVisualizeImgSurrogate because null PURL: " + mmString
                                + " - " + source.Location);
            }

            return(null);
        }
 public RepositoryPatternEntry(Regex pattern, MetaMetadata metaMetadata)
 {
     this.pattern        = pattern;
     this.metaMetadata   = metaMetadata;
 }
 private void InheritFromTopLevelMetaMetadata(MetaMetadata inheritedMmd, MetaMetadataRepository repository, InheritanceHandler inheritanceHandler)
 {
     InheritNonFieldElements(inheritedMmd, inheritanceHandler);
     InheritFrom(repository, inheritedMmd, inheritanceHandler);
 }
 protected void MakeThisFieldUseMmd(String previousName, MetaMetadata mmd)
 {
     // must set this before generatedMmd.inheritMetaMetadata() to meet inheritMetaMetadata() prerequisites
     TypeMmd = mmd;
     // make this field as if is using generatedMmd as type
     Type = mmd.Name;
     ExtendsAttribute = null;
     if (Tag == null)
         Tag = previousName; // but keep the tag name
 }
 protected virtual void InheritNonFieldElements(MetaMetadata inheritedMmd, InheritanceHandler inheritanceHandler)
 {
     Scope = new MmdScope(Scope, inheritedMmd.Scope);
 }
Пример #13
0
        public void Connect()
        {
            DocumentClosureConnectionHelper documentClosureConnectionHelper = new DocumentClosureConnectionHelper(SemanticsSessionScope, Document, this);

            Debug.WriteLine("Connect running from thread: " + Task.CurrentId);
            MetaMetadataCompositeField metaMetadata = Document.MetaMetadata;

            // then try to create a connection using the PURL
            string    userAgentString = metaMetadata.UserAgentString;
            ParsedUri originalPURL    = Document.Location.Value;

            PURLConnection = new PURLConnection(originalPURL);
            if (originalPURL.IsFile)
            {
                // TODO handle local files here!
                var file = PURLConnection.File;
                if (SemanticsPlatformSpecifics.Get().FileIsADictionary(file))
                {
                    // TODO FileDirectoryParser
                    // DocumentParser = DocumentParser.GetDocumentParser(FILE_DIRECTORY_PARSER);
                }
                else
                {
                    PURLConnection.FileConnect();
                    // we already have the correct meta-metadata, having used suffix to construct, or having gotten it from a restore.
                }
            }
            else
            {
                PURLConnection.NetworkConnect(documentClosureConnectionHelper, userAgentString); // HERE!
                if (PURLConnection.Good)
                {
                    Document document = this.Document; // may have changed during redirect processing
                    metaMetadata = document.MetaMetadata;

                    // check for a parser that was discovered while processing a re-direct

                    // if we made PURL connection but could not find parser using container
                    if ((PURLConnection != null) && !originalPURL.IsFile)
                    {
                        string cacheValue = PURLConnection.Response.Headers == null
                                                ? null
                                                : PURLConnection.Response.Headers["X-Cache"];
                        bool cacheHit = cacheValue != null && cacheValue.Contains("HIT");
                        if (metaMetadata.IsGenericMetadata)
                        {
                            // see if we can find more specifc meta-metadata using mimeType
                            MetaMetadataRepository repository = SemanticsSessionScope.MetaMetadataRepository;
                            string       mimeType             = PURLConnection.MimeType;
                            MetaMetadata mimeMmd = mimeType == null ? null : repository.GetMMByMime(mimeType);
                            if (mimeMmd != null && !mimeMmd.Equals(metaMetadata))
                            {
                                // new meta-metadata!
                                if (!mimeMmd.MetadataClass.GetTypeInfo().IsAssignableFrom(document.GetType().GetTypeInfo()))
                                //if (!mimeMmd.MetadataClass.IsAssignableFrom(document.GetType()))
                                {
                                    // more specifc so we need new metadata!
                                    document = (Document)(mimeMmd).ConstructMetadata();
                                    // set temporary on stack
                                    ChangeDocument(document);
                                }
                                metaMetadata = mimeMmd;
                            }
                        }
                    }
                }
            }

            if (DocumentParser == null)
            {
                DocumentParser = DocumentParser.GetDocumentParser(metaMetadata.Parser);
            }
            if (DocumentParser != null)
            {
                DocumentParser.FillValues(SemanticsSessionScope, PURLConnection, metaMetadata, this);
            }
            else
            {
                Debug.WriteLine("WARNING: no parser found: " + metaMetadata);
            }
//            else if (!DocumentParser.isRegisteredNoParser(PURLConnection.getPurl()))
//            {
//                warning("No DocumentParser found: " + metaMetadata);
//            }
        }
 private void InheritNonFieldComponentsFromMM(MetaMetadata inheritedMetaMetadata)
 {
     //Console.WriteLine("InheritNonFieldComponentsFromMM, doing nothing");
 }
 public InheritanceHandler(MetaMetadata rootMmd)
 {
     this.rootMmd = rootMmd;
     this.repository = rootMmd.Repository;
 }
        public void TestArticlesInheritanceRelationships()
        {
            MetaMetadataRepositoryLoader loader             = new MetaMetadataRepositoryLoader();
            SimplTypesScope        metadataTranslationScope = RepositoryMetadataTranslationScope.Get();
            SimplTypesScope        mmdTScope  = MetaMetadataTranslationScope.Get();
            MetaMetadataRepository repository = MetaMetadataRepositoryLoader.ReadDirectoryRecursively(
                "../../../UnitTests/Data/TestRepository",
                mmdTScope,
                metadataTranslationScope);

            repository.TraverseAndInheritMetaMetadata();

            MetaMetadata metadata = repository.GetMMByName("metadata");

            Assert.IsNull(metadata.InheritedMmd);
            Assert.IsTrue(metadata.MmdScope == null || metadata.MmdScope.Count == 0);
            // meta_metadata_name
            MetaMetadataScalarField metadata__meta_metadata_name = (MetaMetadataScalarField)metadata.GetChildMetaMetadata()["meta_metadata_name"];

            Assert.IsNull(metadata__meta_metadata_name.InheritedField);
            Assert.AreSame(metadata, metadata__meta_metadata_name.DeclaringMmd);
            Assert.AreEqual(/*typeof(MetadataStringScalarType).Name*/ "MetadataString", metadata__meta_metadata_name.ScalarTypeP.SimplName);
            // mixins
            MetaMetadataCollectionField metadata__mixins = (MetaMetadataCollectionField)metadata.GetChildMetaMetadata()["mixins"];

            Assert.IsNull(metadata__mixins.InheritedField);
            Assert.AreSame(metadata, metadata__mixins.DeclaringMmd);
            Assert.AreSame(metadata, metadata__mixins.InheritedMmd);

            MetaMetadata document = repository.GetMMByName("document");

            Assert.AreSame(metadata, document.InheritedMmd);
            Assert.IsTrue(document.MmdScope == null || document.MmdScope.Count == 0);
            Assert.AreEqual(metadata__meta_metadata_name, document.GetChildMetaMetadata()["meta_metadata_name"]);
            Assert.AreEqual(metadata__mixins, document.GetChildMetaMetadata()["mixins"]);
            // location
            MetaMetadataScalarField document__location = (MetaMetadataScalarField)document.GetChildMetaMetadata()["location"];

            Assert.IsNull(document__location.InheritedField);
            Assert.AreSame(document, document__location.DeclaringMmd);
            // additional_locations
            MetaMetadataCollectionField document__additional_locations = (MetaMetadataCollectionField)document.GetChildMetaMetadata()["additional_locations"];

            Assert.IsNull(document__additional_locations.InheritedField);
            Assert.AreSame(document, document__additional_locations.DeclaringMmd);
            Assert.IsNull(document__additional_locations.InheritedMmd);

            MetaMetadata article = repository.GetMMByName("article");
            MetaMetadata author  = article.MmdScope["author"];

            Assert.AreSame(metadata, author.InheritedMmd);
            Assert.AreEqual(metadata__meta_metadata_name, author.GetChildMetaMetadata()["meta_metadata_name"]);
            Assert.AreEqual(metadata__mixins, author.GetChildMetaMetadata()["mixins"]);
            // name
            MetaMetadataScalarField author__name = (MetaMetadataScalarField)author.GetChildMetaMetadata()["name"];

            Assert.IsNull(author__name.InheritedField);
            Assert.AreSame(author, author__name.DeclaringMmd);
            // affiliation
            MetaMetadataScalarField author__affiliation = (MetaMetadataScalarField)author.GetChildMetaMetadata()["affiliation"];

            //Assert.IsNull(author__affiliation.InheritedField);
            Assert.AreSame(author, author__affiliation.DeclaringMmd);

            MetaMetadata source = article.MmdScope["source"];

            Assert.AreSame(document, source.InheritedMmd);
            Assert.AreEqual(metadata__meta_metadata_name, source.GetChildMetaMetadata()["meta_metadata_name"]);
            Assert.AreEqual(metadata__mixins, source.GetChildMetaMetadata()["mixins"]);
            Assert.AreEqual(document__additional_locations, source.GetChildMetaMetadata()["additional_locations"]);
            // archive_name
            MetaMetadataScalarField source__archive_name = (MetaMetadataScalarField)source.GetChildMetaMetadata()["archive_name"];

            Assert.IsNull(source__archive_name.InheritedField);
            Assert.AreSame(source, source__archive_name.DeclaringMmd);
            // location
            MetaMetadataScalarField source__location = (MetaMetadataScalarField)source.GetChildMetaMetadata()["location"];

            Assert.AreSame(document__location, source__location.InheritedField);
            Assert.IsFalse(document__location.Hide);
            Assert.IsTrue(source__location.Hide);
            // year_of_publication
            MetaMetadataScalarField source__year_of_publication = (MetaMetadataScalarField)source.GetChildMetaMetadata()["year_of_publication"];

            Assert.IsNull(source__year_of_publication.InheritedField);
            Assert.AreSame(source, source__year_of_publication.DeclaringMmd);
            // isbn
            MetaMetadataScalarField source__isbn = (MetaMetadataScalarField)source.GetChildMetaMetadata()["isbn"];

            Assert.IsNull(source__isbn.InheritedField);
            Assert.AreSame(source, source__isbn.DeclaringMmd);

            Assert.AreSame(document, article.InheritedMmd);
            Assert.IsTrue(article.MmdScope.Count == 2);
            Assert.AreEqual(metadata__meta_metadata_name, article.GetChildMetaMetadata()["meta_metadata_name"]);
            Assert.AreEqual(metadata__mixins, article.GetChildMetaMetadata()["mixins"]);
            Assert.AreEqual(document__location, article.GetChildMetaMetadata()["location"]);
            Assert.AreEqual(document__additional_locations, article.GetChildMetaMetadata()["additional_locations"]);
            // title
            MetaMetadataScalarField article__title = (MetaMetadataScalarField)article.GetChildMetaMetadata()["title"];

            Assert.IsNull(article__title.InheritedField);
            Assert.AreSame(article, article__title.DeclaringMmd);
            // authors
            MetaMetadataCollectionField article__authors = (MetaMetadataCollectionField)article.GetChildMetaMetadata()["authors"];

            Assert.IsNull(article__authors.InheritedField);
            Assert.AreSame(article, article__authors.DeclaringMmd);
            Assert.AreSame(author, article__authors.InheritedMmd);
            // source
            MetaMetadataCompositeField article__source = (MetaMetadataCompositeField)article.GetChildMetaMetadata()["source"];

            Assert.IsNull(article__source.InheritedField);
            Assert.AreSame(article, article__source.DeclaringMmd);
            Assert.AreSame(source, article__source.InheritedMmd);
            // pages
            MetaMetadataScalarField article__pages = (MetaMetadataScalarField)article.GetChildMetaMetadata()["pages"];

            Assert.IsNull(article__pages.InheritedField);
            Assert.AreSame(article, article__pages.DeclaringMmd);

            MetaMetadata paper = repository.GetMMByName("paper");
            MetaMetadata tag   = paper.MmdScope["tag"];

            Assert.AreSame(metadata, tag.InheritedMmd);
            Assert.AreEqual(metadata__meta_metadata_name, tag.GetChildMetaMetadata()["meta_metadata_name"]);
            Assert.AreEqual(metadata__mixins, tag.GetChildMetaMetadata()["mixins"]);
            // tag_name
            MetaMetadataScalarField tag__tag_name = (MetaMetadataScalarField)tag.GetChildMetaMetadata()["tag_name"];

            Assert.IsNull(tag__tag_name.InheritedField);
            Assert.AreSame(tag, tag__tag_name.DeclaringMmd);
            // link
            MetaMetadataScalarField tag__link = (MetaMetadataScalarField)tag.GetChildMetaMetadata()["link"];

            Assert.IsNull(tag__link.InheritedField);
            Assert.AreSame(tag, tag__link.DeclaringMmd);

            Assert.AreSame(article, paper.InheritedMmd);
            Assert.IsTrue(paper.MmdScope.Count == 1);
            Assert.AreEqual(metadata__meta_metadata_name, paper.GetChildMetaMetadata()["meta_metadata_name"]);
            Assert.AreEqual(metadata__mixins, paper.GetChildMetaMetadata()["mixins"]);
            Assert.AreEqual(document__location, paper.GetChildMetaMetadata()["location"]);
            Assert.AreEqual(document__additional_locations, paper.GetChildMetaMetadata()["additional_locations"]);
            Assert.AreEqual(article__title, paper.GetChildMetaMetadata()["title"]);
            // Assert.AreSame(article__authors, paper.GetChildMetaMetadata()["authors"]);
            Assert.AreEqual(article__source, paper.GetChildMetaMetadata()["source"]);
            Assert.AreEqual(article__pages, paper.GetChildMetaMetadata()["pages"]);
            // authors: TODO
            // abstract_field
            MetaMetadataScalarField paper__abstract_field = (MetaMetadataScalarField)paper.GetChildMetaMetadata()["abstract_field"];

            Assert.IsNull(paper__abstract_field.InheritedField);
            Assert.AreSame(paper, paper__abstract_field.DeclaringMmd);
            // references
            MetaMetadataCollectionField paper__references = (MetaMetadataCollectionField)paper.GetChildMetaMetadata()["references"];

            Assert.IsNull(paper__references.InheritedField);
            Assert.AreSame(paper, paper__references.DeclaringMmd);
            Assert.AreSame(paper, paper__references.InheritedMmd);
            // citations
            MetaMetadataCollectionField paper__citations = (MetaMetadataCollectionField)paper.GetChildMetaMetadata()["citations"];

            Assert.IsNull(paper__citations.InheritedField);
            Assert.AreSame(paper, paper__citations.DeclaringMmd);
            Assert.AreSame(paper, paper__citations.InheritedMmd);
            // keywords
            MetaMetadataCollectionField paper__keywords = (MetaMetadataCollectionField)paper.GetChildMetaMetadata()["keywords"];

            Assert.IsNull(paper__keywords.InheritedField);
            Assert.AreSame(paper, paper__keywords.DeclaringMmd);
            Assert.AreEqual(/*typeof(MetadataStringScalarType).Name*/ "MetadataString", paper__keywords.ChildScalarType.SimplName);

            MetaMetadata acm_paper = repository.GetMMByName("acm_paper");

            Assert.AreSame(paper, acm_paper.InheritedMmd);
            Assert.IsTrue(acm_paper.MmdScope == null || acm_paper.MmdScope.Count == 0);
            Assert.AreEqual(metadata__meta_metadata_name, acm_paper.GetChildMetaMetadata()["meta_metadata_name"]);
            Assert.AreEqual(metadata__mixins, acm_paper.GetChildMetaMetadata()["mixins"]);
            Assert.AreEqual(document__location, acm_paper.GetChildMetaMetadata()["location"]);
            Assert.AreEqual(document__additional_locations, acm_paper.GetChildMetaMetadata()["additional_locations"]);
            Assert.AreEqual(article__source, acm_paper.GetChildMetaMetadata()["source"]);
            Assert.AreEqual(article__pages, acm_paper.GetChildMetaMetadata()["pages"]);
            Assert.AreEqual(paper__abstract_field, acm_paper.GetChildMetaMetadata()["abstract_field"]);
            Assert.AreEqual(paper__references, acm_paper.GetChildMetaMetadata()["references"]);
            Assert.AreEqual(paper__citations, acm_paper.GetChildMetaMetadata()["citations"]);
            Assert.AreEqual(paper__keywords, acm_paper.GetChildMetaMetadata()["keywords"]);
            // title
            MetaMetadataScalarField acm_paper__title = (MetaMetadataScalarField)acm_paper.GetChildMetaMetadata()["title"];

            Assert.AreEqual(article__title, acm_paper__title.InheritedField);
            Assert.AreSame(article, acm_paper__title.DeclaringMmd);
            // authors
            MetaMetadataCollectionField acm_paper__authors = (MetaMetadataCollectionField)acm_paper.GetChildMetaMetadata()["authors"];

            // Assert.AreSame(article__authors, acm_paper__authors.InheritedField); // should
            // inherit from paper__authors
            Assert.AreSame(article, acm_paper__authors.DeclaringMmd);
            Assert.AreSame(author, acm_paper__authors.InheritedMmd);
            // authors.name
            MetaMetadataScalarField acm_paper__authors__name = (MetaMetadataScalarField)acm_paper__authors.GetChildMetaMetadata()["name"];

            //Assert.AreEqual(author__name, acm_paper__authors__name.InheritedField);
            Assert.AreSame(author, acm_paper__authors__name.DeclaringMmd);
            Assert.AreEqual("location", acm_paper__authors__name.NavigatesTo);
            // authors.affiliation
            MetaMetadataScalarField acm_paper__authors__affiliation = (MetaMetadataScalarField)acm_paper__authors.GetChildMetaMetadata()["affiliation"];

            Assert.AreEqual("./affiliation", acm_paper__authors__affiliation.Xpath);
        }
Пример #17
0
 public void TakeSemanticOperations(MetaMetadata metaMetadata, Metadata metadata)
 {
     TakeSemanticOperations(metaMetadata, metadata, metaMetadata.SemanticActions);
 }
Пример #18
0
        public async Task <Document> PerformDownload()
        {
            // change status
            lock (downloadStatusLock)
            {
                if (!(DownloadStatus == DownloadStatus.QUEUED || DownloadStatus == DownloadStatus.UNPROCESSED))
                {
                    return(Document); // if not queued or unprocessed, it must either hasn't enter the queue or has already been processed.
                }
                DownloadStatus = DownloadStatus.CONNECTING;
            }

            Document.SemanticsSessionScope = SemanticsSessionScope;

            ParsedUri location = Document == null ? null : Document.Location == null ? null : Document.Location.Value;

            Debug.WriteLine("Calling connect from thread: " + Task.CurrentId);
            DateTime time = DateTime.Now;

            Connect();
            Debug.WriteLine("Completed connect: " + DateTime.Now.Subtract(time).TotalMilliseconds);

            if (PURLConnection != null && PURLConnection.Good) // && DocumentParser != null)
            {
                // parsing
                lock (downloadStatusLock)
                {
                    DownloadStatus = DownloadStatus.PARSING;
                }
                // TODO display message from DocumentParser
                MetaMetadata mmd = Document.MetaMetadata as MetaMetadata;
                // TODO before semantic actions

                //This call returns void
                //Parser is responsible for setting result in the documentClosure.TaskCompletionSource
                DocumentParser.Parse();

                await GetMetadata();

                // TODO after semantic actions

                lock (downloadStatusLock)
                {
                    DownloadStatus = DownloadStatus.DOWNLOAD_DONE;
                }
            }
            else
            {
                Debug.WriteLine("ERROR: cannot perform downloading on " + location);
            }
            // Document.DownloadDone = true;
            Document.DownloadAndParseDone();

            if (PURLConnection != null)
            {
                PURLConnection.Recycle();
            }
            PURLConnection = null;

            return(Document);
        }
        protected MetaMetadata GenerateMetaMetadata(String previousName, MetaMetadata inheritedMmd)
        {
            String generatedName = getGeneratedMmdName2(previousName);

            // generate the mmd and set attributes
            MetaMetadata generatedMmd = new MetaMetadata
                                            {
                                                Name = generatedName,
                                                PackageName = PackageName,
                                                Type = null,
                                                TypeMmd = inheritedMmd,
                                                ExtendsAttribute = inheritedMmd.Name,
                                                Repository = Repository,
                                                Visibility = Visibility.PACKAGE,
                                                Scope =
                                                    new MmdScope(this.Scope,
                                                                                         inheritedMmd.Scope)
                                            };
            if (SchemaOrgItemtype != null)
                generatedMmd.SchemaOrgItemtype = SchemaOrgItemtype;
            generatedMmd.SetNewMetadataClass(true);

            // move nested fields (they will be cloned later)
            if (kids != null && kids.Count > 0)
            {
                foreach (String kidKey in this.kids.Keys)
                {
                    MetaMetadataField kid;
                    kids.TryGetValue(kidKey, out kid);
                    generatedMmd.Kids.Put(kidKey, kid);
                    kid.Parent = generatedMmd;
                }
                kids.Clear();
            }
            MakeThisFieldUseMmd(previousName, generatedMmd);
            return generatedMmd;
        }